-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotes.sh
More file actions
80 lines (67 loc) · 2.25 KB
/
Copy pathnotes.sh
File metadata and controls
80 lines (67 loc) · 2.25 KB
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
#!/bin/bash
# mark a to-do as complete
check_off_todo() {
local options=""
local line_num=0
while IFS= read -r line; do
((line_num++))
if [[ -n "$line" ]]; then
options+="$line_num $line\n"
fi
done < "$todo_filename"
if [[ -z "$options" ]]; then
zenity --info --text="No uncompleted to-dos to check off."
return
fi
local selected=$(echo -e "$options" | zenity --list --column="Line" --column="To-Do" --title="Check Off a To-Do")
if [[ -n "$selected" ]]; then
local line_num=$(echo "$selected" | awk '{print $1}')
sed -i "${line_num}d" "$todo_filename"
fi
}
# directories and files
notes_dir="$HOME/Documents/Notes"
todo_filename="$notes_dir/todo.txt"
mkdir -p "$notes_dir"
# dates
current_date=$(date +"%Y-%m-%d")
note_filename="$notes_dir/$current_date.txt"
# do fancy shit if note or todo file doesn't exist
if [[ ! -r "$note_filename" ]]; then
echo "----------------------------------------" >> "$note_filename"
echo "Date: $current_date" >> "$note_filename"
echo "----------------------------------------" >> "$note_filename"
fi
if [[ ! -r "$todo_filename" ]]; then
echo "----------------------------------------" >> "$todo_filename"
echo "To-Do List" >> "$todo_filename"
echo "----------------------------------------" >> "$todo_filename"
fi
# loop for adding notes or to-dos
while true; do
choice=$(zenity --list --title="Choose Action" --column="Options" "Add Note or todo" "View To-Do List" "Check Off To-Do" "Quit")
case "$choice" in
"Add Note or todo")
new_content=$(zenity --entry --title="Create a Note or To-Do" --text="Enter your note or to-do:")
action=$(zenity --list --title="Save As" --column="Options" "Note" "To-Do")
if [[ $action == "Note" ]]; then
if [[ ! -z "$new_content" ]]; then
echo "$(date +"%H:%M") $new_content" >> "$note_filename"
fi
elif [[ $action == "To-Do" ]]; then
if [[ ! -z "$new_content" ]]; then
echo "$new_content" >> "$todo_filename"
fi
fi
;;
"View To-Do List")
zenity --text-info --filename="$todo_filename"
;;
"Check Off To-Do")
check_off_todo
;;
"Quit")
exit 0
;;
esac
done