-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotes.sh
93 lines (84 loc) · 1.76 KB
/
notes.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
#!/usr/bin/env bash
function printOptions {
local -a options=("${!1}") # "create array option exluding builtin param 1"
for (( j=0; j<${#options[@]}; j+=2)); do
local label=${options[$j]}
local task=${options[$j+1]}
echo "${label}) $task"
done
}
function main_menu {
local MAIN_OPTIONS=(
1 'Recent Notes'
2 'New Note'
11 'Exit'
)
printOptions MAIN_OPTIONS[@]
echo "Select an option: "
read SELECTION
case "$SELECTION" in
1)
recent_note
;;
2)
new_note
;;
11)
exit
;;
esac
#go back to main
main_menu
}
function recent_note {
local -a recents=($(ls ~/notes))
RECENTSEL=-1
while [[ $RECENTSEL < 0 || $RECENTSEL > ${#recents[@]} ]]; do
echo ${#recents[@]}
echo "Select a note ([h]ome, [q]uit):"
for (( j=0; j<${#recents[@]}; j+=1)); do
local task=${recents[$j]}
echo "${j}) $task"
done
read RECENTSEL
echo $RECENTSEL
if [[ $RECENTSEL = q ]]; then
exit
elif [[ $RECENTSEL = h ]]; then
notes.sh && exit
fi
done
vim ~/notes/${recents[$RECENTSEL]} && exit
}
function new_note {
read -p "Project ID ([h]ome, [q]uit): " PROJ
if [[ $PROJ = q ]]; then
exit
elif [[ $PROJ = h ]]; then
main_menu
fi
read -p "Notes ID ([h]ome, [q]uit): " IDENT
if [[ $IDENT = q ]]; then
exit
elif [[ $IDENT = h ]]; then
main_menu
fi
NAME="notes-${PROJ}-$(date +%Y%m%d)-$IDENT"
FILE=~/notes/${NAME}.txt
if [[ -e $FILE ]]; then
while [[ -e $FILE ]]; do
read -p "Provide a unique ID ([h]ome, [q]uit): " IDENT
NAME="notes-${PROJ}-$(date +%Y%m%d)-$IDENT"
FILE=~/notes/${NAME}.txt
done
fi
if [[ $IDENT = q ]]; then
exit
elif [[ $IDENT = h ]]; then
main_menu
fi
echo "Creating $FILE..."
touch $FILE
vim $FILE && exit
}
main_menu