From: Fred T. Hamster Date: Tue, 14 Jan 2025 15:04:59 +0000 (-0500) Subject: nice mode to find how a script is defined X-Git-Tag: 2.140.189^2~35 X-Git-Url: https://feistymeow.org/gitweb/?a=commitdiff_plain;h=e56a085d8d11c0229d5e2a54ceacb64216a1358b;p=feisty_meow.git nice mode to find how a script is defined --- diff --git a/scripts/core/functions.sh b/scripts/core/functions.sh index b1c7c903..85a8fac8 100644 --- a/scripts/core/functions.sh +++ b/scripts/core/functions.sh @@ -134,6 +134,24 @@ if [ -z "$skip_all" ]; then ############## + # attempts to find a script by the name passed in, as either a function or an alias. + # if the alias points directly at a script file, then that will be printed to stdout. + function locate_script() + { + local script_name="$1"; shift + maybe_found="$(type "$script_name" | sed -n -r -e "s/^.*is aliased to .[^ ]+ (.*).$/\1/p")" + if [ -z "$maybe_found" ]; then + maybe_found="$(alias "$script_name" | sed -n -r -e "s/^.*is aliased to .[^ ]+ (.*).$/\1/p")" + if [ -z "$maybe_found" ]; then + # last ditch effort is to just show what "type" outputs. + maybe_found="$(type "$script_name")" + fi + fi + echo "$maybe_found" + } + + ############## + function fm_username() { # see if we can get the user name from the login name. oddly this sometimes doesn't work.