5 # choice: Display an X dialogue to allow a choice.
6 # Usage: choice [-t <timeout>] <description> <text>:<ret> [<text>:<ret> ...]
7 # Example: choice "File exists" "Replace:1" "Back up:2" "No action:0"
11 echo >&2 "Usage: choice [-t <timeout>] <description> <text>:<ret> [<text>:<ret> ...]"
15 while getopts ":t:" arg; do
17 t) timeout="$OPTARG";;
23 description="$1"; shift
24 [ -z "$description" ] && usage
25 for i in ${1+"$@"}; do
26 [ "${i/:/}" = "$i" ] && usage
30 if which zenity 2>/dev/null | grep ^/ &>/dev/null; then
31 [ ! -z "$timeout" ] && timeout="--timeout=$timeout"
32 for i in ${1+"$@"}; do
33 args="$args \"${i/:/\" }"
35 ret=$(eval zenity --list --text="\"$description\"" --column=Choice --column=hidden --hide-column=2 --print-column=2 $args $timeout)
38 [ ! -z "$timeout" ] && timeout="-timeout $timeout"
39 for i in ${1+"$@"}; do
43 eval exec xmessage -center $timeout -buttons $args "$description"