Skip to content

Instantly share code, notes, and snippets.

@omni-
Created May 12, 2016 02:26
Show Gist options
  • Save omni-/2c1ee92dc257f03cff1c576f05543ac9 to your computer and use it in GitHub Desktop.
Save omni-/2c1ee92dc257f03cff1c576f05543ac9 to your computer and use it in GitHub Desktop.
es() {
local OPTIND
python=''
elevated=''
file=''
while getopts 'f:ps' flag; do
case "${flag}" in
f) file="${OPTARG}" ;;
p) python='true' ;;
s) elevated='true' ;;
\?) echo "E: Unrecognized option ${flag}" && return ;;
esac
done
if [ $# -eq 0 ] ; then
echo "E: Not enough args" && return
fi
if [ -z "${file}" ] ; then
echo "E: Must specify file" && return
fi
sPath="$scripts/$file"
if [ ! -f "$sPath" ] ; then
echo "E: File not found"
else
chmod a+x $sPath
if [ "$python" = "true" ] ; then
python $sPath
elif [ "$elevated" = "true" ] ; then
sudo -s . $sPath
else
. $sPath
fi
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment