-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsttm.sh
executable file
·96 lines (83 loc) · 1.53 KB
/
sttm.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
#!/bin/bash
# Simple terminal task manager
# https://github.com/prototipo/sttm
usage="Usage: $(basename "$0") [-h] add <string>|remove <number>|show|clear
where:
-h show this help text
add <string> add a new task to the task list
edit <number> <string> edit the number-th task of the list
remove <number> remove the number-th task of the list
show show the whole task list
clear clear the whole task list"
tasks_file="$HOME/sttm/tasks"
if [ $# -lt 1 ]; then
echo "$usage"
exit 1
fi
case "$1" in
-h)
echo "$usage"
exit
;;
add)
if [ $# -lt 2 ]; then
echo "$usage"
exit 1
else
echo "${@:2}" >> $tasks_file
fi
exit
;;
edit)
if [ $# -lt 3 ]; then
echo "$usage"
exit 1
else
re='^[0-9]+$'
d='d'
rest="${@:3}"
if [[ $2 =~ $re ]] && [ $2 -le $(wc -l < $tasks_file) ]; then
# sed -i "$2$d" $tasks_file
sed -i "$2s/.*/$rest/" $tasks_file
exit
else
echo "$usage"
exit 1
fi
fi
exit
;;
remove)
if [ $# -lt 2 ]; then
echo "$usage"
exit 1
else
re='^[0-9]+$'
d='d'
if [[ $2 =~ $re ]] && [ $2 -le $(wc -l < $tasks_file) ]; then
sed -i "$2$d" $tasks_file
exit
else
echo "$usage"
exit 1
fi
fi
exit
;;
show)
exec<$tasks_file
count=0
echo "TODO list:"
while read LINE
do
count=$(( $count + 1))
echo "$count) $LINE"
done
exit
;;
clear)
rm $tasks_file
touch $tasks_file
exit
;;
esac