-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdmenu_tnotes
More file actions
executable file
·109 lines (96 loc) · 3.97 KB
/
Copy pathdmenu_tnotes
File metadata and controls
executable file
·109 lines (96 loc) · 3.97 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
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
#!/bin/sh
#This file is part of the TinyTools distribution (https://github.com/Calebe94/TinyTools).
#Copyright (C) 2021 TinyTools
#
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program. If not, see <http://www.gnu.org/licenses/>.
#
####################################################################################################
# Variables used in the script.
####################################################################################################
DMENU_ITEMS="/tmp/dmenu_items"
DMENU_ARGS=$@
TNOTES=$(pwd)/tnotes
###################################################################################################
# add_note function
# takes 1(one) argument: the name of the element to add.
###################################################################################################
add_note()
{
if [ "$@" ] && [ "$@" != "[add]" ]; then
note="$@"
$TNOTES -n "$TNOTES_PATH/$@"
xdg-open "$TNOTES_PATH/${note%.*}.md"
fi
}
###################################################################################################
# rename_note function
# takes 1(one) argument: the name of the element to rename.
###################################################################################################
rename_note()
{
new_note=$(echo "" | dmenu -p "Rename" $DMENU_ARGS)
echo "moving $@ to $new_note"
$TNOTES --mv "$TNOTES_PATH/$@" "$TNOTES_PATH/${new_note%.*}.md"
show_notes
}
###################################################################################################
# remove_note function
# takes 1(one) argument: the name of the element to remove.
###################################################################################################
remove_note()
{
$TNOTES --rm "$TNOTES_PATH/$@"
show_notes
}
###################################################################################################
# note_selection function
# takes 1(one) argument: the name of the element selected.
# The function now uses DMENU to show some options to you.
###################################################################################################
note_selection()
{
chosen="$@"
action=$(echo "[open]\n[rename]\n[delete]\n[back]" | dmenu -p "$chosen" $DMENU_ARGS)
case $action in
*"[open]"*) xdg-open "$TNOTES_PATH/$chosen";;
*"[rename]"*) rename_note "$chosen" ;;
*"[delete]"*) remove_note "$chosen" ;;
*"[back]"*) show_notes ;;
esac
}
###################################################################################################
# show_notes function
# Lists the notes
###################################################################################################
show_notes()
{
actions="[add]"
echo $actions > $DMENU_ITEMS
$TNOTES -l $TNOTES_PATH >> $DMENU_ITEMS
sed -i "s|$TNOTES_PATH||g" $DMENU_ITEMS
chosen=$(cat $DMENU_ITEMS | dmenu -p "Notes" $DMENU_ARGS)
if grep -Fxq "$chosen" $DMENU_ITEMS
then
case "$chosen" in
*"[add]"*) todo=$(echo "" | dmenu -p "Add:" $DMENU_ARGS) ; add_note "$chosen"; show_notes ;;
*) note_selection "$chosen";;
esac
else
add_note "$chosen"
fi
}
###################################################################################################
############################################## MAIN ###############################################
###################################################################################################
show_notes