-
-
Notifications
You must be signed in to change notification settings - Fork 242
/
watson.completion
126 lines (120 loc) · 4.36 KB
/
watson.completion
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# Bash completion support for watson
#
# Install this as `/etc/bash_completion.d/watson` and restart your shell.
_watson_complete () {
local cur cmd commands frames projects tags
commands='add cancel config edit frames help log merge projects remove rename report restart start status stop sync tags'
cur=${COMP_WORDS[COMP_CWORD]}
cmd=${COMP_WORDS[1]}
case ${COMP_CWORD} in
1)
COMPREPLY=($(compgen -W "$commands" -- "$cur" )) ;;
*)
case "${cmd}" in
add)
# check if we are inputting a date, in which case return empty completion by returning
prev="${COMP_WORDS[COMP_CWORD-1]}"
if [[ ${prev} == "-f" ]] || [[ ${prev} == "--from" ]] || [[ ${prev} == "-t" ]] || [[ ${prev} == "--to" ]]; then
return 0
fi
if ((COMP_CWORD < 6)); then
# we assume that --from/-f with parameter and -t/--to with parameter need to exist (as they are required)
# and if they are not there COMP_CWORD < 6 we allow completion only for that
COMPREPLY=($(compgen -W "-f --from -t --to" -- ${cur}))
elif ((COMP_CWORD < 7)); then
# we assume that project is one word string and therefore if COMP_CWORD < 7 its not there
local IFS=$'\n'
projects="$(watson projects | sed -e 's/ /\\\\ /g')"
COMPREPLY=($(compgen -W "$projects" -- ${cur}))
else
# finally in all other cases we expect to be filling in tags
local IFS=$'\n'
tags="$(watson tags | sed -e 's/ /\\\\ /g' | awk '$0="+"$0')"
COMPREPLY=($(compgen -W "$tags" -- ${cur}))
fi
;;
config)
COMPREPLY=($(compgen -W "-e --edit" -- ${cur})) ;;
edit)
frames="$(watson frames)"
COMPREPLY=($(compgen -W "$frames" -- ${cur}))
;;
help)
COMPREPLY=($(compgen -W "$commands" -- "$cur" )) ;;
log|report)
case "$3" in
-p|--project)
local IFS=$'\n'
projects="$(watson projects | sed -e 's/ /\\\\ /g')"
COMPREPLY=($(compgen -W "$projects" -- ${cur}))
;;
-T|--tag)
local IFS=$'\n'
tags="$(watson tags | sed -e 's/ /\\\\ /g')"
COMPREPLY=($(compgen -W "$tags" -- ${cur}))
;;
*)
COMPREPLY=($(compgen -W "-a -c -C -d -f -g -G -j -m -p -t -T -w -y --all --current --no-current --pager --no-pager --from --to --project --tag --day --week --month --year --luna --json" -- ${cur})) ;;
esac
;;
merge)
case "${cur}" in
-*)
COMPREPLY=($(compgen -W "-f --force" -- ${cur})) ;;
*)
COMPREPLY=($(compgen -o filenames -f -- ${cur}))
;;
esac
;;
remove)
case "${cur}" in
-*)
COMPREPLY=($(compgen -W "-f --force" -- ${cur})) ;;
*)
frames="$(watson frames)"
COMPREPLY=($(compgen -W "$frames" -- ${cur}))
;;
esac
;;
rename)
local IFS=$'\n'
case "$3" in
project)
projects="$(watson projects | sed -e 's/ /\\\\ /g')"
COMPREPLY=($(compgen -W "$projects" -- ${cur}))
;;
tag)
tags="$(watson tags | sed -e 's/ /\\\\ /g')"
COMPREPLY=($(compgen -W "$tags" -- ${cur}))
;;
esac
;;
restart)
case "${cur}" in
-*)
COMPREPLY=($(compgen -W "-s --stop -S --no-stop" -- ${cur})) ;;
*)
frames="$(watson frames)"
COMPREPLY=($(compgen -W "$frames" -- ${cur}))
;;
esac
;;
start)
local IFS=$'\n'
if [[ $COMP_CWORD -eq 2 ]]; then
projects="$(watson projects | sed -e 's/ /\\\\ /g')"
COMPREPLY=($(compgen -W "$projects" -- ${cur}))
else
tags="$(watson tags | sed -e 's/ /\\\\ /g' | awk '$0="+"$0')"
COMPREPLY=($(compgen -W "$tags" -- ${cur}))
fi
;;
status)
COMPREPLY=($(compgen -W "-e --elapsed -p --project -t --tags" -- ${cur}))
;;
esac
;;
esac
return 0
}
complete -F _watson_complete watson