3 # choice: Display an X dialogue to allow a choice.
4 # Usage: choice [-t <timeout>] <description> <text>:<ret> [<text>:<ret> ...]
5 # Example: choice "File exists" "Replace:1" "Back up:2" "No action:0"
9 echo >&2 "Usage: choice [-t <timeout>] <description> <text>:<ret> [<text>:<ret> ...]"
13 while getopts ":t:" arg; do
15 t) timeout="$OPTARG";;
21 description="$1"; shift
22 [ -z "$description" ] && usage
23 for i in ${1+"$@"}; do
24 [ "${i/:/}" = "$i" ] && usage
28 if which zenity 2>/dev/null | grep ^/ &>/dev/null; then
29 [ ! -z "$timeout" ] && timeout="--timeout=$timeout"
30 for i in ${1+"$@"}; do
31 args="$args \"${i/:/\" }"
33 ret=$(eval zenity --list --text="\"$description\"" --column=Choice --column=hidden --hide-column=2 --print-column=2 $args $timeout)
36 [ ! -z "$timeout" ] && timeout="-timeout $timeout"
37 for i in ${1+"$@"}; do
41 eval exec xmessage -center $timeout -buttons $args "$description"