blob: 6b13ae870291da4808fcb8c46ae1a5e4db372b64 (
plain)
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
|
_tasker_task_dirs() {
local root d name
if [[ -d "$PWD/tasks" ]]; then
root="$PWD/tasks"
else
root="$PWD"
fi
shopt -s nullglob
for d in "$root"/*/; do
name="${d%/}"
name="${name##*/}"
if [[ "$name" =~ ^[0-9]{2}-[0-9]{2}-[0-9]{2}\ [0-9]{2}:[0-9]{2}:[0-9]{2}(\.[0-9]+)?$ ]]; then
printf '%s\n' "$name"
fi
done
}
_tasker_completion() {
local cur prev words cword subcommand
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
local commands="new list set delete"
subcommand=""
for word in "${COMP_WORDS[@]:1}"; do
case "$word" in
new|list|set|delete)
subcommand="$word"
break
;;
esac
done
if [[ -z "$subcommand" ]]; then
COMPREPLY=( $(compgen -W "$commands" -- "$cur") )
return 0
fi
case "$subcommand" in
new)
case "$prev" in
-p|-d)
return 0
;;
esac
COMPREPLY=( $(compgen -W "-p -d" -- "$cur") )
;;
list)
case "$prev" in
-s|--status)
COMPREPLY=( $(compgen -W "OPEN IN_PROGRESS CLOSED" -- "$cur") )
return 0
;;
-p|--priority|--min-priority|-c|--contains)
return 0
;;
esac
COMPREPLY=( $(compgen -W "-s --status -p --priority --min-priority -c --contains" -- "$cur") )
;;
set)
case "$prev" in
-s|--status)
COMPREPLY=( $(compgen -W "OPEN IN_PROGRESS CLOSED" -- "$cur") )
return 0
;;
-n|--name|-p|--priority|-d|--desc)
return 0
;;
esac
if [[ "$cur" == -* ]]; then
COMPREPLY=( $(compgen -W "-n --name -s --status -p --priority -d --desc" -- "$cur") )
else
COMPREPLY=( $(compgen -W "$(_tasker_task_dirs)" -- "$cur") )
fi
;;
delete)
COMPREPLY=( $(compgen -W "$(_tasker_task_dirs)" -- "$cur") )
;;
esac
}
complete -F _tasker_completion tasker
|