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
" | sed 's/ /_/')"
27 $MSGBOX operation cancelled
35 NAME
="$($ENTRY "enter the name of the
script"| sed 's/ /_/')"
37 $MSGBOX operation cancelled
41 cat >> "$NAME" << _END
51 #arg1: the file/dir to rename
52 function rename_file
()
54 NEW_NAME
=$
($ZENITY --entry --text "enter new name" --entry-text $1)
56 $MSGBOX operation cancelled
65 ACTION
=$
($ZENITY --column "Select action" --list rename remove
)
67 $MSGBOX operation cancelled
68 elif [ "$ACTION" == "remove" ]; then
69 PASSWORD
=$
($ZENITY --entry --text "enter \"DELETE this MENU\"" --entry-text "pleeease, don't kill meeee")
70 if [ $?
-gt 0 -o $PASSWORD != "DELETE this MENU"]; then
71 $MSGBOX operation cancelled
75 elif [ "$ACTION" == "rename" ]; then
83 ACTION
=$
($ZENITY --column "Select action" --list edit rename remove
)
85 $MSGBOX "operation cancelled"
86 elif [ "$ACTION" == "edit" ]; then
89 elif [ "$ACTION" == "remove" ]; then
90 PASSWORD
="$($ZENITY --entry --text "enter
\"DELETE this FILE
\"" --entry-text "noooo
, save meeee
")"
91 if [ $?
-gt 0 -o $PASSWORD != "DELETE this FILE"]; then
92 $MSGBOX operation cancelled
97 elif [ "$ACTION" == "rename" ]; then
102 #edit the menus in the current path
106 TITLE
="scripta - EDIT"
107 menu_items
--desc-prefix "edit--" back new_submenu new_script quit
109 if [ "$SELECTED" == $SEP ]; then
111 elif [ "$SELECTED" == "back" ]; then
113 elif [ "$SELECTED" == "new_submenu" ]; then
115 elif [ "$SELECTED" == "new_script" ]; then
117 elif [ -d $SELECTED ]; then
119 elif [ -f $SELECTED ]; then
126 # arg1: bash script which defines a "run" function
131 $ERROR "Error, the file doesn't define a run() function"
140 function do_nothing
()
145 # arg1: return value of zenity
146 # arg2: selected command
147 function parse_menu_commons
()
149 if [ $1 -gt 0 ]; then
150 echo exiting with status
$1
154 if [ "$2" == "quit" ]; then
159 #arg1: prefix for the description part
163 find -maxdepth 1 -type d |
165 sed 's/.*\/\([^/]*\)/\1/' |
167 sed -e :a
-e '$ P; /$/N; s/\n/ /; ta;'|
170 sed "s/\([a-z]\+\) /\1 $1\1... /g"
173 find -maxdepth 1 -type f |
175 sed "s/.*\/\([^/]*\)/\1 $1\1/" |
176 sed -e :a
-e '$ P; /$/N; s/\n/ /; ta;'|
180 # arg1-n: additional menu entries
181 function menu_items
()
186 while [ $# -gt 0 ]; do
187 if [ "$1" == "--desc-prefix" ]; then
191 ADDITIONAL
="$ADDITIONAL $1 $1"
196 get_items
"$DESC_PREFIX"
198 SELECTED
=$
($ZENITY --title "$TITLE" --hide-column 1 --column Command
--column Operation
--list $SUBMENUS $MENU_ITEMS $SEP $SEP $ADDITIONAL)
199 parse_menu_commons $?
"$SELECTED"
203 change_dir
$ROOT_MENU_DIR
206 menu_items back edit quit
208 if [ "$SELECTED" == $SEP ]; then
210 elif [ "$SELECTED" == "edit" ]; then
212 elif [ "$SELECTED" == "back" ]; then
214 elif [ -d $SELECTED ]; then
216 elif [ -f $SELECTED ]; then