3 # a menu of customized quick shortcuts
5 if ! [ -e ~/.config/instantos/quickmenu ]; then
6 mkdir -p ~/.config/instantos/quickmenu
9 cd ~/.config/instantos/quickmenu || exit 1
13 while [ -z "$CHOICE" ]; do
14 if [ -z "$(ls)" ]; then
15 CHOICE="$(echo 'edit menu
16 close' | instantmenu -bw 4 -C -l 15 -w -1)"
19 CHOICE="$(ls -p | sed -e '$aedit menu\nclose' | instantmenu -bw 4 -C -l 15 -w -1)"
21 if [ -e "$CHOICE" ]; then
22 if [ -d "$CHOICE" ]; then
23 cd "$CHOICE" || exit 1
29 if grep -Eiq '^(close|edit)' <<<"$CHOICE"; then
39 # create a new script with the given arguments
41 ADDCHOICE="$(echo 'enter command
53 COMMAND="$(imenu -i 'enter command')"
54 echo "$COMMAND" >>"$SCRIPTNAME"
58 echo "# instantOS quickmenu script" >>"$SCRIPTNAME"
59 st -e nvim -c ":e $(realpath "$SCRIPTNAME")"
62 echo "#!/bin/bash" >"$SCRIPTNAME"
63 ADDTEMPLATE="$(echo 'run in terminal
64 enable argument dialog' | imenu -b)"
65 if grep -q 'terminal' <<<"$ADDTEMPLATE"; then
66 echo "enabling terminal"
67 echo '#instantosterm' >>"$SCRIPTNAME"
70 if grep -q 'argument' <<<"$ADDTEMPLATE"; then
71 echo "enabling argument"
72 echo '#instantosarg' >>"$SCRIPTNAME"
77 [ -e "$SCRIPTNAME" ] && rm "$SCRIPTNAME"
84 cd "$(cat /tmp/quickpath)" || exit 1
85 ADDCHOICE="$(echo 'add entry
89 new category' | instantmenu -bw 4 -C -l 7 -w -1)"
90 if [ -z "$ADDCHOICE" ]; then
97 REMOVECHOICE="$(ls -p | instantmenu -bw 4 -C -l 7 -w -1)"
98 if [ -d "$REMOVECHOICE" ] && [ -n "$(ls "$REMOVECHOICE/")" ]; then
99 imenu -m "category is not empty"
101 elif ! [ -e "$REMOVECHOICE" ]; then
102 imenu -m "selection $REMOVECHOICE invalid"
105 if imenu -c "remove $REMOVECHOICE"; then
106 if [ -d "$REMOVECHOICE" ]; then
107 rm -rf "$REMOVECHOICE"
115 CATEGORYNAME="$(imenu -i 'enter category name')"
116 [ -n "$CATEGORYNAME" ] && mkdir "$CATEGORYNAME"
119 echo "adding new entry"
120 SCRIPTNAME="$(imenu -i 'enter name')"
122 if [ -e "$SCRIPTNAME" ]; then
123 imenu -m "script $SCRIPTNAME already existing"
127 if [ -z "$SCRIPTNAME" ]
132 touch "$SCRIPTNAME" || {
133 imenu -m "invalid script name"
139 echo "editing existing entry"
140 EDITCHOICE="$(ls -p | instantmenu -bw 4 -C -l 7 -w -1)"
141 [ -z "$EDITCHOICE" ] && exit
142 if [ -d "$EDITCHOICE" ]; then
143 imenu -m "selection is not a script"
145 elif ! [ -e "$EDITCHOICE" ]; then
146 imenu -m "selection $EDITCHOICE invalid"
149 st -e nvim -c ":e $(realpath "$EDITCHOICE")"
152 echo "renaming entry"
153 EDITCHOICE="$(ls -p | instantmenu -bw 4 -C -l 7 -w -1)"
154 [ -z "$EDITCHOICE" ] && exit
156 if ! [ -e "$EDITCHOICE" ]; then
157 imenu -m "$EDITCHOICE does not exist"
160 NEWNAME="$(imenu -i 'enter new name')"
161 [ -z "$NEWNAME" ] && exit
162 mv "$EDITCHOICE" "$NEWNAME"
168 QUICKCHOICE="$(pickscript)"
171 if [ -z "$QUICKCHOICE" ]; then
175 case "$QUICKCHOICE" in
184 if ! [ -e "$QUICKCHOICE" ]; then
186 echo "choice $QUICKCHOICE not found"
190 if grep -q "^#instantosarg" "$QUICKCHOICE"; then
191 QUICKARGS="$(imenu -i options)"
192 [ -z "$QUICKARGS" ] && exit
195 if grep -q "^#instantosterm" "$QUICKCHOICE"; then
196 chmod +x "$QUICKCHOICE"
197 st -e bash -c "$QUICKCHOICE $QUICKARGS"
199 bash "$QUICKCHOICE" "$QUICKARGS"