-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotetaker.sh
executable file
·187 lines (162 loc) · 5.14 KB
/
notetaker.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/bin/bash
# One night project no.1
# NoteTaker - minimal note taking script
# Features:
# - Add note
# - Delete note
# - Edit note
# - Open note in editor
# - Copy note to clipboard
# - List all notes
# Requirements:
# - FZF (sudo apt install fzf)
# - xclip (sudo apt install xclip)
# - nano (sudo apt install nano)
# Author: @roboT-23
# Version: 0.1
# Date: 2023-11-06
# License: MIT
#Set whatever directory you want
notes_directory="$HOME/projects/notetaker/notes"
# Create a directory if not already created one
if [ ! -d "$notes_directory" ]; then
mkdir "$notes_directory"
fi
# List all notes
show_notes() {
clear
echo -e "\e[33m================================#\e[0m"
echo -e "\e[33m===\e[0m Notes list: \e[33m================#\e[0m"
for note in "$notes_directory"/*; do
if [ -f "$note" ]; then
filename=$(basename "$note")
creation_date=$(stat -c %y "$note" | cut -d ' ' -f1)
echo -e "\e[1;34m$filename\e[0m \e[0;32m$creation_date\e[0m"
fi
done
echo -e "\e[33m================================#\e[0m"
}
# Function to add note
add_note() {
clear
echo -e "\e[1;32m+++\e[0m Insert note name \e[1;32m+++#\e[0m"
read note_title
# You can create whatever file format you need - .md/.txt ...
new_note="$notes_directory/$note_title.txt"
if [ -e "$new_note" ]; then
echo "Note with this name already exists, do you want to edit? (Y/N): "
read response
if [ "$response" == "Y" ] || [ "$response" == "y" ]; then
nano "$new_note"
echo -e "\e[32m===\e[0m Editing... \e[32m========#\e[0m"
echo -e "\e[33m*==============================*#\e[0m"
else
echo -e "\e[31m===\e[0m Operation cancelled \e[31m========#\e[0m"
echo -e "\e[33m*==============================*#\e[0m"
fi
else
echo -e "\e[33m===\e[0m Note was added \e[33m=============#\e[0m"
echo -e "\e[33m*===============================*\e[0m"
nano "$new_note"
fi
}
# Delete note function
delete_note() {
clear
show_notes
echo -e "\e[36m===\e[0m Select note to delete \e[36m======#\e[0m"
note_to_delete=$(ls "$notes_directory" | fzf) # FZF
if [ -e "$notes_directory/$note_to_delete" ]; then
rm "$notes_directory/$note_to_delete"
echo "$note_to_delete"
echo -e "\e[31m===\e[0m Note was deleted \e[31m===========#\e[0m"
else
echo -e "\e[33m===\e[0m Note does not exist \e[33m==========#\e[0m"
fi
}
# Edit function
edit_note() {
clear
show_notes
echo -e "\e[33m*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*#\e[0m"
echo -e "\e[32m~~~\e[0m Select note to edit \e[32m~~~#\e[0m "
note_to_edit=$(ls "$notes_directory" | fzf) # FZF
echo "$note_to_edit"
if [ -e "$notes_directory/$note_to_edit" ]; then
echo -e "\e[32m~~~\e[0m Editing... \e[32m ~~~#\e[0m"
echo -e "\e[33m*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*#\e[0m"
nano "$notes_directory/$note_to_edit" # Change nano to your favorite editor
fi
}
#Copy to clipboard
copy_note() {
clear
show_notes
note_to_copy=$(ls "$notes_directory" | fzf)
if [ -f "$notes_directory/$note_to_copy" ]; then
echo -e "\e[33m*##############################*#\e[0m"
echo -e "\e[33m###\e[0m Copying to clibpboard... \e[33m####\e[0m"
echo "$note_to_copy"
echo -e "\e[33m*##############################*#\e[0m"
cat "$notes_directory/$note_to_copy" | xclip -selection clipboard
fi
}
# Opens note in editor
open_note() {
clear
show_notes
echo -e "\e[36m===\e[0m Select note to open \e[36m=======#\e[0m"
note_to_open=$(ls "$notes_directory" | fzf) # FZF
if [ -e "$notes_directory/$note_to_open" ]; then
echo "$note_to_open"
nano "$notes_directory/$note_to_open"
else
echo -e "\e[33m===\e[0m Note does not exist \e[33m==========#\e[0m"
fi
}
# Main routine
while true; do
echo -e "\e[42m#########--\e[0m NoteTaker \e[42m--#########\e[0m"
echo -e "\e[32m================================#\e[0m"
echo -e "\e[36m***\e[0m Select option: \e[36m***#\e[0m"
echo -e "\e[1;35m===\e[0m 1. List all \e[1;35m===#\e[0m"
echo -e "\e[1;32m+++\e[0m 2. Add note \e[1;32m+++#\e[0m "
echo -e "\e[1;31m---\e[0m 3. Delete note \e[1;31m---#\e[0m"
echo -e "\e[1;33m~~~\e[0m 4. Edit note \e[1;33m~~~#\e[0m"
echo -e "\e[1;43m###\e[0m 5. Copy note \e[1;43m####\e[0m"
echo -e "\e[1;32mOOO\e[0m 6. Open note \e[1;32mOOO#\e[0m"
echo -e "\e[1;31mXXX\e[0m 7. Exit \e[1;31mXXX#\e[0m"
echo -e "\e[32m================================#\e[0m"
read choice
case $choice in
1)
show_notes
;;
2)
add_note
;;
3)
delete_note
;;
4)
edit_note
;;
5)
copy_note
;;
6)
open_note
;;
7)
echo -e "\e[1;33m __"
echo -e "___( o)>"
echo -e "\ <_. )"
echo -e " '---' "
echo -e "\e[1;31mXXX\e[0m Exiting... :q \e[1;31mXXX#\e[0m"
break
;;
*)
echo ""
;;
esac
done