forked from todotxt/todo.txt-cli
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathschedule
executable file
·70 lines (59 loc) · 1.5 KB
/
schedule
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
#!/usr/bin/env bash
action=$1
shift
item=$1
shift
param="$*"
pattern=" t:\([0-9]\{2,4\}[^A-Za-z0-9]\)\{2\}[0-9]\{2,4\}" # not enforcing any particular format
function usage {
echo " $(basename $0) [<item> <date>|<item> mv <date>|<item> rm]"
echo " Set, modify or remove date threshold of an item."
echo " If arguments are omitted, all scheduled tasks are listed."
echo " Intended for use with futureTasks \
(http://github.com/FND/todo.txt-cli/blob/extensions/futureTasks)."
echo " Examples:"
echo " $ $TODO_SH $(basename $0) 42 tomorrow"
echo " $ $TODO_SH $(basename $0) 42 mv 7 days"
echo " $ $TODO_SH $(basename $0) 42 rm"
echo ""
exit
}
function list {
$TODO_FULL_SH -x list | grep "$pattern"
}
function add {
item=$1
threshold=$2
flag=`sed -e "$item!d" "$TODO_FILE" | grep "$pattern"`
if [ -z "$flag" ]; then
$TODO_FULL_SH append $item "t:"`date -d "$threshold" +%F`
else
replace $item "$threshold"
fi
}
function remove {
item=$1
task=`sed -e "$item!d" \
-e "s/^[0-9]* //" \
-e "s/^([A-Z])* //" \
-e "s/$pattern//" \
"$TODO_FILE"` # remove item number, priority and threshold
$TODO_FULL_SH replace $item "$task" # NB: retains priority
}
function replace {
item=$1
threshold=$2
remove $item
add $item "$threshold"
}
[ "$action" = "usage" ] && usage
if [ -z $item ]; then
list
elif [ "$param" = "rm" ]; then
remove $item
elif [[ "$param" == mv* ]]; then # XXX: obsolete
threshold=${param#mv }
replace $item "$threshold"
else
add $item "$param"
fi