forked from ttscoff/doing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoing.completion.bash
89 lines (70 loc) · 1.96 KB
/
doing.completion.bash
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
# Bash completion for `doing` <http://brettterpstra.com/projects/doing>
# Completes commands, views, and section titles
_doing_show() {
OLD_IFS="$IFS"
local token=${COMP_WORDS[$COMP_CWORD]}
IFS=$'\t'
local words=$(doing sections)
IFS="$OLD_IFS"
if [[ "$token" == --* ]]; then
COMPREPLY=( $( compgen -W '--boolean --count --age --sort --times --totals --csv' -- $token ) )
elif [[ "$token" == -* ]]; then
COMPREPLY=( $( compgen -W '-b -c -a -s -t --boolean --count --age --sort --times --totals --csv' -- $token ) )
else
local nocasematchWasOff=0
shopt nocasematch >/dev/null || nocasematchWasOff=1
(( nocasematchWasOff )) && shopt -s nocasematch
local w matches=()
OLD_IFS="$IFS"
IFS=$'\t'‰
for w in $words; do
if [[ "$w" == "$token"* ]]; then
matches+=("${w// /\ }")
fi
done
IFS="$OLD_IFS"
(( nocasematchWasOff )) && shopt -u nocasematch
COMPREPLY=("${matches[@]}")
fi
}
_doing_view() {
OLD_IFS="$IFS"
local token=${COMP_WORDS[$COMP_CWORD]}
IFS=$'\t'
local words=$(doing views)
IFS="$OLD_IFS"
if [[ "$token" == --* ]]; then
COMPREPLY=( $( compgen -W '--section--count --csv --times --totals' -- $token ) )
elif [[ "$token" == -* ]]; then
COMPREPLY=( $( compgen -W '-s -c -t --section--count --csv --times --totals' -- $token ) )
else
local nocasematchWasOff=0
shopt nocasematch >/dev/null || nocasematchWasOff=1
(( nocasematchWasOff )) && shopt -s nocasematch
OLD_IFS="$IFS"
IFS=$'\t'
local w matches=()
for w in $words; do
if [[ "$w" == "$token"* ]]; then matches+=("$w"); fi
done
IFS="$OLD_IFS"
(( nocasematchWasOff )) && shopt -u nocasematch
COMPREPLY=("${matches[@]}")
fi
}
_doing()
{
local last="${@: -1}"
local token=${COMP_WORDS[$COMP_CWORD]}
if [[ $last == "view" ]]; then
_doing_view
elif [[ $last =~ (show|archive|-s|--s|-t) ]]; then
_doing_show
else
OLD_IFS="$IFS"
IFS=$'\n'
COMPREPLY=( $(compgen -W "$(doing help -c)" -- $token) )
IFS="$OLD_IFS"
fi
}
complete -F _doing doing