-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtdm.sh
executable file
·66 lines (51 loc) · 1.31 KB
/
tdm.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
#!/bin/bash
change_first_letter() {
local file_path="$1"
local line_number="$2"
local new_first_letter="$3"
if [[ ! -f "$file_path" ]]; then
echo "File not found: $file_path"
return 1
fi
local total_lines=$(wc -l < "$file_path")
if (( line_number <= 0 || line_number > total_lines )); then
echo "Invalid line number: $line_number"
return 1
fi
sed -i "${line_number}s/^\(.\)/$new_first_letter/" "$file_path"
echo "Changes applied"
}
# Unix based systems support for now
storage=~/.tdm.txt
if test -e "$storage"; then
:
else
touch "$storage"
fi
action=$1
if [[ "clear" == "$action" ]]; then
rm ~/.tdm.txt
echo "Tasks cleared"
fi
if [[ "new" == "$action" ]]; then
task_name="$2"
echo "✗- $task_name" >> "$storage"
echo "New task added"
fi
if [[ "$action" == "ls" ]]; then
cat -n "$storage"
fi
if [[ "$action" == "lsd" ]]; then
grep -n '^✓' "$storage" | awk -F: '{printf "(%d) %s\n", $1, $2}'
fi
if [[ "$action" == "lstd" ]]; then
grep -n '^✗' "$storage" | awk -F: '{printf "(%d) %s\n", $1, $2}'
fi
if [[ "set-done" == "$action" ]]; then
task_id=$2
change_first_letter "$storage" $task_id "✓"
fi
if [[ "set-due" == "$action" ]]; then
task_id=$2
change_first_letter "$storage" $task_id "✗"
fi