shell-base/modules/utility/sudo.lib
kebler.net 99c01d4bb7 add sudo module with Sudo function for running functions or alias as sudo
add install-shell-repo library for easy install of other shell repos (host, network)
2023-02-15 07:08:24 -08:00

21 lines
No EOL
521 B
Bash

#!/bin/bash
fsudo () # run a function as sudo
{
[[ "$(type -t $1)" == "function" ]] &&
ARGS="$@" && sudo bash -c "$(declare -f $1); $ARGS"
}
function Sudo {
local firstArg=$1
if [ $(type -t $firstArg) = function ]
then
shift && command sudo bash -c "$(declare -f $firstArg);$firstArg $*"
elif [ $(type -t $firstArg) = alias ]
then
alias sudo='\sudo '
eval "sudo $@"
else
command sudo "$@"
fi
}