2 # Copyright 2009, Roberto Previdi
5 ZENITY
="zenity --width=400 --height=400"
6 MSGBOX
="$ZENITY --info --text "
7 ERROR
="$ZENITY --error --text "
8 ENTRY
="$ZENITY --entry --text "
9 EDITFILE
="$ZENITY --text-info --editable --filename "
12 SEP
="==================="
15 # arg1: relative/absolute path to switch to
25 NAME
="$($ENTRY "enter the name of the menu
")"
27 $MSGBOX operation cancelled
35 NAME
="$($ENTRY "enter the name of the
script")"
37 $MSGBOX operation cancelled
41 cat >> "$NAME" << _END
54 ACTION
=$
($ZENITY --column "Select action" --list rename remove
)
56 $MSGBOX operation cancelled
57 elif [ "$ACTION" == "remove" ]; then
58 PASSWORD
=$
($ZENITY --entry --text "enter \"DELETE this MENU\"" --entry-text "pleeease, don't kill meeee")
59 if [ $?
-gt 0 -o $PASSWORD != "DELETE this MENU"]; then
60 $MSGBOX operation cancelled
64 elif [ "$ACTION" == "rename" ]; then
65 NEW_NAME
=$
($ENTRY "enter new name" --entry-text $1)
67 $MSGBOX operation cancelled
77 ACTION
=$
($ZENITY --column "Select action" --list edit rename remove
)
79 $MSGBOX operation cancelled
80 elif [ "$ACTION" == "edit" ]; then
83 elif [ "$ACTION" == "remove" ]; then
84 PASSWORD
="$($ZENITY --entry --text "enter
\"DELETE this FILE
\"" --entry-text "noooo
, save meeee
")"
85 if [ $?
-gt 0 -o $PASSWORD != "DELETE this FILE"]; then
86 $MSGBOX operation cancelled
91 elif [ "$ACTION" == "rename" ]; then
92 NEW_NAME
=$
($ZENITY --entry --text "enter new name" --entry-text $1)
94 $MSGBOX operation cancelled
101 #edit the menus in the current path
105 TITLE
="scripta - EDIT"
106 menu_items
--desc-prefix "edit--" back new_submenu new_script quit
108 if [ "$SELECTED" == $SEP ]; then
110 elif [ "$SELECTED" == "back" ]; then
112 elif [ "$SELECTED" == "new_submenu" ]; then
114 elif [ "$SELECTED" == "new_script" ]; then
116 elif [ -d $SELECTED ]; then
118 elif [ -f $SELECTED ]; then
125 # arg1: bash script which defines a "run" function
130 $ERROR "Error, the file doesn't define a run() function"
139 function do_nothing
()
144 # arg1: return value of zenity
145 # arg2: selected command
146 function parse_menu_commons
()
148 if [ $1 -gt 0 ]; then
149 echo exiting with status
$1
153 if [ "$2" == "quit" ]; then
158 #arg1: prefix for the description part
162 find -maxdepth 1 -type d |
164 sed 's/.*\/\([^/]*\)/\1/' |
166 sed -e :a
-e '$ P; /$/N; s/\n/ /; ta;'|
169 sed "s/\([a-z]\+\) /\1 $1\1... /g"
172 find -maxdepth 1 -type f |
174 sed "s/.*\/\([^/]*\)/\1 $1\1/" |
175 sed -e :a
-e '$ P; /$/N; s/\n/ /; ta;'|
179 # arg1-n: additional menu entries
180 function menu_items
()
185 while [ $# -gt 0 ]; do
186 if [ "$1" == "--desc-prefix" ]; then
190 ADDITIONAL
="$ADDITIONAL $1 $1"
195 get_items
"$DESC_PREFIX"
197 SELECTED
=$
($ZENITY --title "$TITLE" --hide-column 1 --column Command
--column Operation
--list $SUBMENUS $MENU_ITEMS $SEP $SEP $ADDITIONAL)
198 parse_menu_commons $?
"$SELECTED"
202 change_dir
$ROOT_MENU_DIR
205 menu_items back edit quit
207 if [ "$SELECTED" == $SEP ]; then
209 elif [ "$SELECTED" == "edit" ]; then
211 elif [ "$SELECTED" == "back" ]; then
213 elif [ -d $SELECTED ]; then
215 elif [ -f $SELECTED ]; then