44 lines
908 B
Bash
44 lines
908 B
Bash
#!/bin/sh
|
|
|
|
# using "helpers." fake namespace to avoid name collisions with installed tools
|
|
# and builtins, so we can properly check existance with command -V
|
|
|
|
helpers.yesno(){
|
|
|
|
# usage:
|
|
# if helpers.yesno
|
|
# then
|
|
# whatever it is you want to do
|
|
# fi
|
|
|
|
echo "(y/N)"
|
|
read optin
|
|
|
|
case $optin in
|
|
y*|Y*)
|
|
return 0 # true
|
|
;;
|
|
*)
|
|
return 1 # false
|
|
;;
|
|
esac
|
|
}
|
|
|
|
helpers.checkhelp(){
|
|
|
|
# to use this just add "helpers.checkhelp $1" to your script
|
|
# right after importing util.sh
|
|
|
|
case $1 in
|
|
-h|--help)
|
|
if command -V helpers.help > /dev/null 2>&1
|
|
then
|
|
helpers.help
|
|
else
|
|
echo "No help for this script. This probably means it doesn't take any parameters."
|
|
echo "Just Run It™"
|
|
fi
|
|
exit
|
|
esac
|
|
}
|