-
Notifications
You must be signed in to change notification settings - Fork 8
/
_timew
108 lines (97 loc) · 2.23 KB
/
_timew
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
#!/usr/bin/env bash
#
# Bash completion for TimeWarrior
#
# Copyright (C) 2017 Thomas Lauf
# taken from https://github.com/lauft/timew-bashcompletion
#
function __get_commands()
{
echo "annotate cancel config continue day delete diagnostics end export extensions fill gaps get help join lengthen modify month move report resize shorten show split start stop summary tag tags track undo untag week"
}
function __get_options()
{
echo "--help --version"
}
function __get_ids()
{
seq -f "@%g" 1 "$( timew get dom.tracked.count )"
}
function __get_tags()
{
timew tags | awk '{if(NR>3)print $1}'
}
function __get_extensions()
{
timew extensions | awk '{if(NR>6)print $1}'
}
function __has_entered_id()
{
for word in "${COMP_WORDS[@]}" ; do
if [[ "${word}" =~ ^@ ]] ; then
return 0
fi
done
return 1
}
function __is_entering_id()
{
if [[ "${COMP_WORDS[COMP_CWORD]}" =~ @[0-9]* ]] ; then
return 0
else
return 1
fi
}
function _timew()
{
local cur first
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
first="${COMP_WORDS[1]}"
case "${first}" in
cancel|config|diagnostics|day|extensions|get|month|show|undo|week)
wordlist=""
;;
continue|delete|join|lengthen|move|resize|shorten|split)
wordlist=$( __get_ids )
;;
export|gaps|start|stop|tags|track)
wordlist=$( __get_tags )
;;
modify)
if __is_entering_id ; then
wordlist=$( __get_ids )
elif __has_entered_id ; then
wordlist=$( '<[date]time>' )
else
wordlist="start end"
fi
;;
summary)
wordlist="$( __get_tags ) :yesterday :day :week :month :quarter :year :lastweek :lastmonth :lastquarter :lastyear today"
;;
tag|untag)
if __is_entering_id ; then
wordlist=$( __get_ids )
elif __has_entered_id ; then
wordlist=$( __get_tags )
else
wordlist=$( __get_ids )
fi
;;
report)
wordlist=$( __get_extensions )
;;
help)
wordlist="$( __get_commands ) interval hints date duration dom"
;;
--*)
wordlist=$( __get_options )
;;
*)
wordlist=$( __get_commands )
;;
esac
COMPREPLY=($( compgen -W "${wordlist}" -- "${cur}" ))
}
complete -F _timew timew