You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I Just whipped this up as part of my bash scripting tools so thought I would share.
copy it to a file, source it and then have fun.
I put in a function smenu_test. When you run it the first time it will pull , build and put smenu in same directory as this script (assuming you are on linux that has a /tmp directory and build-essential or base-devel or the like installed.
smenu the function will call smenu the binary so no need to put it your PATH.
#!/bin/bash
SMENUDIR=$(dirname $BASH_SOURCE)export SMENUDIR
smenu_fetch () {
local repo=https://github.com/p-gen/smenu.git
if git clone $repo /tmp/smenu;thenpushd /tmp/smenu ||return 1
if bash ./build.sh;then
mv smenu "$SMENUDIR"
chmod +x "$SMENUDIR/smenu"elseecho Error attempting to build smenu from the repo
return 1
fi
rm -rf /tmp/smenu
popd||return 1
elseecho Error unable to fetch repo at https://github.com/p-gen/smenu.git
return 1
fi
}
smenu () {
[[ !$SMENUDIR ]] &&echo unable to establish Bash Template directory &&return 2
[[ !-f"$SMENUDIR/smenu" ]] && smenu_fetch
if [[ -f"$SMENUDIR/smenu" ]];then
[[ !$@ ]] &&set -- --help
$SMENUDIR/smenu "$@"elseecho unable to fetch/build smenu, see $BASH_SOURCEreturn 1
fi
}
confirm () {
local res
prompt=${1:-Please confirm your choice:}
res=$( smenu -2 ^Y -1 ^N -3 ^C -s /^N -x cur 10 \ -m "${prompt}:" \<<<"YES NO CANCEL")case$resin
YES)
res=0 ;;
NO)
res=1 ;;
CANCEL)
res=2 ;;
*)
res=3 ;;
esacreturn$res
}
smenu_test () {
echo"testing smenu using a simple confirmation"
confirm "Choose or abort and see return value"echo$?if confirm "Choose or abort and an if statement is evaluated";thenecho"confirm returned 0/true (i.e. YES), proceed"elseecho"confirm returned other than 0, i.e. false, do nothing"fi
}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I Just whipped this up as part of my bash scripting tools so thought I would share.
copy it to a file, source it and then have fun.
I put in a function
smenu_test
. When you run it the first time it will pull , build and put smenu in same directory as this script (assuming you are on linux that has a /tmp directory and build-essential or base-devel or the like installed.smenu
the function will callsmenu
the binary so no need to put it your PATH.see this gist and below https://gist.github.com/dkebler/fe40cd5ad14f54807c6a975be1d0a1da
Beta Was this translation helpful? Give feedback.
All reactions