-
Notifications
You must be signed in to change notification settings - Fork 0
/
todo
executable file
·115 lines (106 loc) · 2.04 KB
/
todo
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
#! /bin/bash
source "kv-bash"
# Initialize ID
COUNT=`kvget count`
if [[ -z $COUNT ]]
then
kvset count 1
fi
# Add thing with a unique ID
function add_thing() {
thing_to_add="$@"
id=`kvget count`
kvset $id "$thing_to_add"
let "id+=1"
kvset count $id
}
# Delete thing based on ID
function del_thing() {
echo "What've you done, ol' (wo)man?"
echo "-------"
kvlist
echo "-------"
read ID
for idn in $ID; do
kvdel $idn
done
}
# Reorder
function reorder_things() {
id=1
for i in "$KV_USER_DIR/"*; do
if [ -f "$i" ]; then
key="$(basename "$i")"
value=$(kvget "$key")
if((key!= "count"))
then
kvdel $key
kvset $id "$value"
let "id+=1"
fi
fi
done
kvset count $id
}
function show_help() {
echo "This is what I can do: "
echo "todo add <task> : Adds your task along with a Unique ID"
echo "todo upd: Asks for the unique ID and helps you update your task. White space will keep the task as it is"
echo "todo del: Asks for the unique ID of your task and removes it"
echo "todo: Displays your tasks"
echo "todo clear: Clears your tasks"
}
function update {
kvlist &>/dev/null
if [ $? = 6 ] ; then
echo "Add a task before using the update command"
else
echo -n "Task(s) to update: "
read ID
for idn in $ID; do
echo -n "Task $idn should say: "
read newtask
if [ -n "$newtask" ]; then
kvset $idn "$newtask"
else
echo "Task $idn will not be updated"
fi
done
echo ""
echo "Updated list:"
kvlist
fi
}
if(($# > 0))
then
case $1 in
add)
shift
add_thing $@
exit 0
;;
upd)
update
exit 0
;;
del)
del_thing
reorder_things
exit 0
;;
help)
show_help
exit 0
;;
clear)
kvclear
exit 0
;;
*)
echo "Invalid option: $1" >&2
exit 1
;;
esac
else
kvlist
fi