Skip to content

Instantly share code, notes, and snippets.

@EvanOxfeld
Created May 23, 2012 20:45
Show Gist options
  • Save EvanOxfeld/2777686 to your computer and use it in GitHub Desktop.
Save EvanOxfeld/2777686 to your computer and use it in GitHub Desktop.
Nit completion plugin for Oh My ZSH
#compdef nit
#autoload
# Node Issue Tracker
# https://github.com/nearinfinity/node-nit
_assigned_to_me_nits() {
assigned_to_me_nits=(`nit list -o | awk '/Assigned to me/ {for(i=1; i<=NF; i++) {getline; print $1}}'`)
}
_open_nits() {
open_nits=(`nit list -o | awk '/Open/ {for(i=1; i<=NF; i++) {getline; print $1}}'`)
}
_nit_actions() {
nit_actions=(`nit help | awk '/Actions:/ {for(i=1; i<=12; i++) {getline; print $1}}'`)
}
local -a _1st_arguments
_1st_arguments=(
'add:Adds a task'
'assign:Assign a task to a person.' #todo autocomplete users
'claim:Assign a task to yourself.'
'close:Closes a task.'
'comment:Add a comment to a task.'
'config:Configures nit.' #todo has args
'edit:Edit a task'
'help:help - Shows help' #todo autocomp commands
'init:Initializes a directory for nit' #todo has args
'list:Lists tasks' #todo has args
'show:Shows the specified task'
'web:Creates a web server to view and interact with the tasks.' #todo has args
)
local expl
local -a _assigned_to_me_nits
local -a _open_nits
#TODO: more args?
_arguments \
'(-h)-h[output usage information]' \
'*:: :->subcmds' && return 0
if (( CURRENT == 1 )); then
_describe -t commands "nit subcommand" _1st_arguments
return
fi
case "$words[1]" in
config)
_arguments \
'(--username)--username[The name of the user. (ie John Smith).]' \
'(--email)--email[The email address of the user. (ie john.smith@gmail.com).]' \
'(--editor)--editor[The editor to use to edit tasks. (ie /usr/bin/vi).]' ;; #todo both short & "verbose" options
help)
_nit_actions
_wanted nit_actions expl 'actions' compadd -a nit_actions ;;
assign|claim|close|comment|edit)
_assigned_to_me_nits
_open_nits
_wanted assigned_to_me_nits expl 'assigned to me nits' compadd -a assigned_to_me_nits
_wanted open_nits expl 'open nits' compadd -a open_nits ;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment