-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtodo.sh
executable file
·134 lines (127 loc) · 2.5 KB
/
todo.sh
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/bin/bash
todoDir="$HOME/.todo/"
if [ ! -d $todoDir ]
then
`mkdir $todoDir`
fi
if [ $# -eq 0 ]
then
echo "Error : wrong number of paramaters"
exit
fi
case $1 in
create)
if [ -n "$2" ]
then
echo "This will create a new list with name $2"
if [ -f "$todoDir/$2" ]
then
echo "Error : List with name $2 already exists."
else
if [ -n "$3" ]
then
if [ -f "$todoDir/$3" ]
then
awk -f ./awk/copyTODO.awk $todoDir/$3 > $todoDir/$2
else
echo "Error: List with name $3 does not exist."
fi
else
`touch $todoDir/$2`
fi
fi
else
echo "Error: List name is missing"
fi;;
remove)
if [ -n "$2" ]
then
echo "This will delete an existing list with name $2"
if [ -f "$todoDir/$2" ]
then
`rm -f $todoDir/$2`
else
echo "Error : List with name $2 does not exist"
fi
else
echo "Error: List name is missing"
fi;;
add)
if [ -n "$2" ]
then
if [ ! -f $todoDir/$2 ]
then
echo "Error : List with name $2 does not exist"
exit
fi
if [ -n "$3" ]
then
echo "New todo item : \"$3\" in list with name $2"
echo "TODO:$3" >> "$todoDir/$2"
else
echo "Error: New todo item is missing"
fi
else
echo "Error: List name is missing"
fi;;
done)
if [ -n "$2" ]
then
if [ ! -f $todoDir/$2 ]
then
echo "Error : List with name $2 does not exist"
fi
if [ -n "$3" ]
then
echo "item number $3 in list with name $2 is DONE"
awk -f ./awk/status.awk line=$3 status="DONE" $todoDir/$2 > $todoDir/$2.tmp
mv $todoDir/$2.tmp $todoDir/$2
else
echo "Error: item number is missing"
fi
else
echo "Error: List name is missing"
fi;;
undone)
if [ -n "$2" ]
then
if [ -n "$3" ]
then
echo "item number $3 in list with name $2 is TODO"
awk -f ./awk/status.awk line=$3 status="TODO" $todoDir/$2 > $todoDir/$2.tmp
mv $todoDir/$2.tmp $todoDir/$2
else
echo "Error: item number is missing"
fi
else
echo "Error: List name is missing"
fi;;
delete)
if [ -n "$2" ]
then
if [ -n "$3" ]
then
echo "item number $3 is deleted from list with name $2"
awk -f ./awk/remove.awk line=$3 $todoDir/$2 > $todoDir/$2.tmp
mv $todoDir/$2.tmp $todoDir/$2
else
echo "Error: item number is missing"
fi
else
echo "Error: List name is missing"
fi;;
show)
if [ -n "$2" ]
then
if [ -f $todoDir/$2 ]
then
awk -f ./awk/show.awk $todoDir/$2
else
echo "Error : List with name $2 does not exist"
fi
else
echo "Error : List name is missing"
fi;;
*)
echo "Error : invalid parameters. Try 'todo --help' for valid options";;
esac