forked from giomatfois62/rofi-desktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrofi-notes.sh
executable file
·107 lines (87 loc) · 1.94 KB
/
rofi-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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash
# https://github.com/christianholman/rofi_notes
# default values
AUTHOR=$(whoami)
NOTES_FOLDER="$HOME/.notes"
NOTES_EDITOR=xdg-open
if [[ ! -d "${NOTES_FOLDER}" ]]; then
mkdir -p "$NOTES_FOLDER"
fi
get_notes() {
ls "${NOTES_FOLDER}"
}
edit_note() {
note_location=$1
$NOTES_EDITOR "$note_location"
}
delete_note() {
local note=$1
local action=$(echo -e "Yes\nNo" | rofi -dmenu -p "Are you sure you want to delete $note? ")
case $action in
"Yes")
rm "$NOTES_FOLDER/$note"
main
;;
"No")
main
esac
}
note_context() {
local note=$1
local note_location="$NOTES_FOLDER/$note"
local action=$(echo -e "Edit\nDelete" | rofi -dmenu -p "$note > ")
case $action in
"Edit")
edit_note "$note_location"
exit 0;;
"Delete")
delete_note "$note"
exit 0;;
esac
exit 1
}
new_note() {
local title=$(echo -e "Cancel" | rofi -dmenu -p "Input title: ")
case "$title" in
"Cancel")
main
;;
*)
local file=$(echo "$title" | sed 's/ /_/g;s/\(.*\)/\L\1/g')
local template=$(cat <<- END
---
title: $title
date: $(date --rfc-3339=seconds)
author: $AUTHOR
---
# $title
END
)
note_location="$NOTES_FOLDER/$file.md"
if [ "$title" != "" ]; then
echo "$template" > "$note_location" | edit_note "$note_location"
exit 0
fi
;;
esac
}
main()
{
local all_notes="$(get_notes)"
local first_menu="New"
if [ "$all_notes" ];then
first_menu="New\n${all_notes}"
fi
local note=$(echo -e "$first_menu" | rofi -dmenu -p "Note: ")
case $note in
"New")
new_note
;;
"")
exit 1;;
*)
note_context "$note" && exit 0 # handle esc key in note_context
esac
exit 1
}
main