-
Notifications
You must be signed in to change notification settings - Fork 0
/
todo
executable file
·54 lines (45 loc) · 1.36 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
#!/bin/sh
# -=- Simple To Do List Manager -=-
# Not very useful imo, but i'm bored so ehh...
# TODO: Clean and improve this thing, look shit rn
DATAFILE="${XDG_DATA_HOME:-$HOME/.local/share}/zi_todo"
noTask() {
echo "You have no task."
exit
}
lineBreak() {
echo "$1" | sed 's/\\n/\n/g'
}
getTodo() {
[ -z "$TODO" ] && noTask
case "$1" in
[0-9]*) ID=$(echo $1 | sed -r 's/^0*([0-9])/\1/g')
[ -z "${SPECIFIC:=$(echo "$TODO" | grep "^\[$ID\]")}" ] && echo "There's no task with id '$ID'." && exit
lineBreak "$SPECIFIC" && exit;;
"") lineBreak "$TODO" && exit;;
esac
}
[ -e $DATAFILE ] && TODO=$(cat -b $DATAFILE | sed -r 's/^\s+([0-9]*)\s+/[\1] /g') || touch $DATAFILE
case "$1" in
help) echo "Usage: todo [OPTION] [TASK|TASK ID]
Options:
help show this message
add add new task
remove remove a task
info show info of a task
list show your tasks";;
add)
[ ! -z "$2" ] && echo "${@:2}" >> $DATAFILE && echo "Added task:"; echo " ${@:2}" && exit
echo "Usage: todo add [TASK]"
;;
remove|rm)
if [ ! -z $2 ]; then
[ ! -z "$TODO" ] && echo "$TODO" | grep -v "^\[$2\]" | sed "s/^\[[0-9]\] //g" > $DATAFILE && echo "Task has been removed"
# noTask
fi
;;
clear) : > $DATAFILE && echo "Todo list has been cleared";;
info) [ ! -z "$2" ] && getTodo "$2" || echo "Usage: todo info [TASK ID]";;
list|ls|*) getTodo;;
esac
# getTodo $1