Skip to content

Commit 95983e7

Browse files
author
David Revelo
committed
Fixed exit button, fixed screen size
1 parent 64bb2c5 commit 95983e7

File tree

1 file changed

+36
-18
lines changed

1 file changed

+36
-18
lines changed

di-exec.sh

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,6 @@ OUTPUT=/tmp/output.sh.$$
88
# trap and delete temp files
99
trap "rm $OUTPUT; rm $INPUT; exit" SIGHUP SIGINT SIGTERM
1010

11-
function display_output(){
12-
local h=${1-10} # box height default 10
13-
local w=${2-41} # box width default 41
14-
local t=${3-Output} # box title
15-
dialog --backtitle "Select the command to execute: " --title "${t}" --clear --msgbox "$(<$OUTPUT)" ${h} ${w}
16-
#
17-
}
18-
1911
declare -a CAPTIONS
2012
declare -a COMMANDS
2113

@@ -38,22 +30,48 @@ do OPTIONS="$OPTIONS $i ${CAPTIONS[$i]}"
3830
done
3931

4032

33+
# Define the dialog exit status codes
34+
: ${DIALOG_OK=0}
35+
: ${DIALOG_CANCEL=1}
36+
: ${DIALOG_HELP=2}
37+
: ${DIALOG_EXTRA=3}
38+
: ${DIALOG_ITEM_HELP=4}
39+
: ${DIALOG_ESC=255}
40+
41+
4142
while true
4243
do
43-
44+
exec 3>&1
4445
### display main menu ###
45-
dialog \
46-
--clear \
47-
--backtitle "di-exec" \
48-
--title "[ SELECT A COMMAND ]" \
49-
--menu "Use UP/DOWN arrow keys, Choose the command" 15 150 4 \
50-
$OPTIONS 2>"${INPUT}"
51-
52-
menuitem=$(<"${INPUT}")
46+
menuitem=$( dialog \
47+
--clear \
48+
--backtitle "di-exec" \
49+
--title "[ SELECT A COMMAND ]" \
50+
--cancel-label "Exit" \
51+
--menu "Use UP/DOWN arrow keys, Choose the command" \
52+
20 150 12 \
53+
$OPTIONS \
54+
2>&1 1>&3 )
55+
56+
exit_status=$?
57+
58+
exec 3>&-
59+
case $exit_status in
60+
$DIALOG_CANCEL)
61+
clear
62+
echo "Program terminated."
63+
exit
64+
;;
65+
$DIALOG_ESC)
66+
clear
67+
echo "Program aborted." >&2
68+
exit 1
69+
;;
70+
esac
5371

5472
clear
5573
echo "Executing! \"${COMMANDS[$menuitem]}\" " $'\n\n'
56-
sleep 2
74+
sleep 1
5775
eval ${COMMANDS[$menuitem]}
5876
read -p "Press [Enter] key to continue..."
5977

0 commit comments

Comments
 (0)