Skip to content

Commit 861800c

Browse files
committed
Add tusker executable
1 parent d711d0e commit 861800c

File tree

1 file changed

+112
-0
lines changed

1 file changed

+112
-0
lines changed

tusker

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
#!/bin/bash
2+
3+
HELP_MSG="Tusker : A dead simple todo manager
4+
5+
Add a new task : tusker add TASK_DESCRIPTION
6+
Mark a task as done : tusker check TASK_ID
7+
Mark a task as undone : tusker uncheck TASK_ID
8+
Delete a task : tusker del TASK_ID
9+
Show existing tasks : tusker show
10+
"
11+
12+
FILE_DIR="$HOME/.cache/tusker"
13+
FILE_NAME="$FILE_DIR/tasks.txt"
14+
TICK='\xE2\x9C\x93'
15+
CROSS='\xE2\x9D\x8C'
16+
DELIM='$$$'
17+
18+
function check_args() {
19+
if [ $# -eq 1 ] && ([ "$1" = "show" ] || [ "$1" = "help" ]); then
20+
return
21+
fi
22+
23+
if [ $# -gt 1 ] && [ "$1" = "add" ]; then
24+
return
25+
fi
26+
27+
if [ $# -ne 2 ]; then
28+
echo "Not a valid command. Type 'tusker help' for usage."
29+
exit
30+
fi
31+
}
32+
33+
function create_file() {
34+
mkdir -p $FILE_DIR
35+
if [ ! -e "$FILE_NAME" ]; then
36+
touch "$FILE_NAME"
37+
fi
38+
}
39+
40+
function add_task() {
41+
local task_desc="$1"
42+
local current_timestamp=$(date +"%d %B %Y %H:%M:%S")
43+
echo -e "$CROSS $DELIM $task_desc $DELIM $current_timestamp" >> $FILE_NAME
44+
}
45+
46+
function delete_task() {
47+
local task_id=$1
48+
sed -i -e "$task_id""d" $FILE_NAME
49+
}
50+
51+
function check_task() {
52+
local task_id=$1
53+
sed -i "$task_id s/^./$TICK/" $FILE_NAME
54+
}
55+
56+
function uncheck_task() {
57+
local task_id=$1
58+
sed -i "$task_id s/^./$CROSS/" $FILE_NAME
59+
}
60+
61+
function show_tasks() {
62+
local line_count=$(wc -l $FILE_NAME | awk '{print $1}')
63+
64+
if [ $line_count -eq 0 ]; then
65+
echo "You're all caught up!!"
66+
return
67+
fi
68+
69+
nl $FILE_NAME | column -t -s $DELIM
70+
}
71+
72+
73+
function main() {
74+
check_args $@
75+
create_file
76+
77+
local action=$1
78+
79+
case $action in
80+
add)
81+
shift
82+
add_task "$*"
83+
echo "Task added"
84+
;;
85+
86+
del)
87+
delete_task $2
88+
echo "Task deleted"
89+
;;
90+
91+
check)
92+
check_task $2
93+
echo "Task marked as done"
94+
;;
95+
96+
uncheck)
97+
uncheck_task $2
98+
echo "Task marked as undone"
99+
;;
100+
101+
show)
102+
show_tasks
103+
;;
104+
105+
help)
106+
echo -n -e "$HELP_MSG"
107+
;;
108+
109+
esac
110+
}
111+
112+
main $@

0 commit comments

Comments
 (0)