-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtodo
executable file
·58 lines (47 loc) · 2.05 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
54
55
56
57
58
#!/usr/bin/env bash
## By Davoud Arsalani
## https://github.com/davoudarsalani/scripts
## https://github.com/davoudarsalani/scripts/blob/master/todo
## https://raw.githubusercontent.com/davoudarsalani/scripts/master/todo
## https://davoudarsalani.ir
source "$HOME"/main/scripts/gb
function cp_file_to_kaddy {
cp "$todo_file" "$todo_kaddy_file"
}
todo_file="$HOME"/main/todo/todo
todo_kaddy_file="$(get_kaddy_counterpart "$todo_file")"
readarray -t content < "$todo_file"
main_items=( 'ADD' 'REMOVE' 'EMPTY' '' "${content[@]}" )
main_item="$(pipe_to_rofi "${main_items[@]}" 'header=todo')" || exit 37
case "$main_item" in
ADD )
declare -a add_items ## no members needed here
add_item="$(pipe_to_rofi "${add_items[@]}" 'header=add')" || exit 37
## exit if it already exists
\grep -qw "$add_item" "$todo_file" && msgc 'ERROR' "<span color=\"${orange}\">${add_item}</span> already exists" "$HOME"/main/linux/themes/alert-w.png && exit
{
printf '%s\n' "$add_item" >> "$todo_file"
cp_file_to_kaddy
} && msgn "added <span color=\"${orange}\">${add_item}</span>" ;;
REMOVE )
[ "${content[0]}" ] || {
msgc 'ERROR' 'todo is empty' "$HOME"/main/linux/themes/alert-w.png
exit
}
# remove_items= ## exceptionally skipped this line because we already have the content in the form of an array and can pipe it in the next line
remove_item="$(pipe_to_rofi "${content[@]}" 'header=remove' 'bg=red')" || exit 37
{
sed -i "/^$remove_item$/d" "$todo_file" ## NOTE do NOT replace " with ' in sed
cp_file_to_kaddy
} && msgn "removed <span color=\"${red}\">${remove_item}</span>" ;;
EMPTY )
empty_items=( 'no' 'yes' )
empty_item="$(pipe_to_rofi "${empty_items[@]}" 'header=you sure?')" || exit 37
case "$empty_item" in
yes )
{
: > "$todo_file"
cp_file_to_kaddy
} && msgn 'emptied' ;;
esac ;;
esac