From e56a085d8d11c0229d5e2a54ceacb64216a1358b Mon Sep 17 00:00:00 2001 From: "Fred T. Hamster" Date: Tue, 14 Jan 2025 10:04:59 -0500 Subject: [PATCH] nice mode to find how a script is defined --- scripts/core/functions.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) 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. -- 2.34.1