From b37c5f94005e84f785265ee030e6f36908831654 Mon Sep 17 00:00:00 2001 From: "Fred T. Hamster" Date: Wed, 15 Jan 2025 09:08:46 -0500 Subject: [PATCH] removed an unneeded case and added function check --- scripts/core/functions.sh | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/scripts/core/functions.sh b/scripts/core/functions.sh index 4f56f70b..42004025 100644 --- a/scripts/core/functions.sh +++ b/scripts/core/functions.sh @@ -134,18 +134,30 @@ if [ -z "$skip_all" ]; then ############## - # attempts to find a script by the name passed in, as either a function or an alias. + # attempts to find the script file or at least the defition for a command + # given the command name. if it's an alias or a # if the alias points directly at a script file, then that will be printed to stdout. function locater() { - local script_name="$1"; shift - maybe_found="$(type "$script_name" | sed -n -r -e "s/^.*is aliased to .[^ ]+ (.*).$/\1/p")" + local command_name="$1"; shift + # first test checks whether it's a function or not. we have a special + # check here, since this actually does generate some text using our + # alias finding pattern below, but it's gibberish. better to rule this + # case out first. + maybe_found="$(type "$command_name" 2>/dev/null | grep -i "is a function")" + if [ ! -z "$maybe_found" ]; then + # we found a function, so just dump out its definition. + echo "$(type "$command_name")" + return + fi + # now try searching for a simple alias. + maybe_found="$(type "$command_name" 2>/dev/null | 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 +#wtf? maybe_found="$(alias "$command_name" 2>/dev/null | sed -n -r -e "s/^.*is aliased to .[^ ]+ (.*).$/\1/p")" +#wtf2 if [ -z "$maybe_found" ]; then # last ditch effort is to just show what "type" outputs. - maybe_found="$(type "$script_name")" - fi + maybe_found="$(type "$command_name")" +#wtf3 fi fi echo "$maybe_found" } -- 2.34.1