Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ebcb7aa
commit 3079ab3
Showing
2 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
_ctt() | ||
{ | ||
local cur prev opts cmds projects | ||
COMPREPLY=() | ||
cur="${COMP_WORDS[COMP_CWORD]}" | ||
prev="${COMP_WORDS[COMP_CWORD-1]}" | ||
opts="-h --help -d --debug -v --verbose" | ||
cmds="listprojects track report" | ||
|
||
case "${prev}" in | ||
track|report) | ||
if [[ -d ~/.ctt ]]; then | ||
projects=$(ls ~/.ctt) | ||
else | ||
projects="" | ||
fi | ||
;; | ||
esac | ||
|
||
case "${prev}" in | ||
-*|listprojects) | ||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) | ||
return 0 | ||
;; | ||
track) | ||
opts="-h --help -d --debug -v --verbose --sd --start --ed --end -n --no-comment" | ||
COMPREPLY=( $(compgen -W "${opts} ${projects}" -- ${cur}) ) | ||
return 0 | ||
;; | ||
report) | ||
opts="-h --help -d --debug -v --verbose --sd --start --ed --end -a --all -e --regexp -i --ignore-case -f -format -s --summary" | ||
COMPREPLY=( $(compgen -W "${opts} ${projects}" -- ${cur}) ) | ||
return 0 | ||
;; | ||
*) | ||
;; | ||
esac | ||
|
||
if [[ ${cur} == -* ]]; then | ||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) | ||
return 0 | ||
fi | ||
|
||
COMPREPLY=( $(compgen -W "${cmds}" -- ${cur}) ) | ||
return 0 | ||
} | ||
|
||
complete -F _ctt ctt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#compdef ctt | ||
|
||
_ctt() | ||
{ | ||
local curcontext="$curcontext" state line | ||
typeset -A opt_args | ||
|
||
_arguments \ | ||
'1: :->opts_cmds'\ | ||
'*: :->opts' | ||
|
||
case $state in | ||
opts_cmds) | ||
_arguments '1:Options and commands:(listprojects track report -h --help -d --debug -v --verbose)' | ||
;; | ||
*) | ||
case $words[2] in | ||
track|report) | ||
projects=($(ls ~/.ctt)) | ||
;; | ||
esac | ||
|
||
case $words[2] in | ||
listprojects|-*) | ||
opts=(-h --help -d --debug -v --verbose) | ||
compadd "$@" -- $opts | ||
;; | ||
track) | ||
opts=(-h --help -d --debug -v --verbose --sd --start --ed --end -n --no-comment) | ||
compadd "$@" -- $opts $projects | ||
;; | ||
report) | ||
opts=(-h --help -d --debug -v --verbose --sd --start --ed --end -a --all -e --regexp -i --ignore-case -f -format -s --summary) | ||
compadd "$@" -- $opts $projects | ||
;; | ||
*) | ||
;; | ||
esac | ||
esac | ||
} | ||
|
||
_ctt "$@" |