Skip to content

Instantly share code, notes, and snippets.

@LaptopDev
Created September 2, 2025 22:01
Show Gist options
  • Select an option

  • Save LaptopDev/1e76c60326cf63c9189e9e55800e246a to your computer and use it in GitHub Desktop.

Select an option

Save LaptopDev/1e76c60326cf63c9189e9e55800e246a to your computer and use it in GitHub Desktop.
User/session definition resolver that prints shell definitions for aliases, functions, and exported variables.
showdef () { # Check if alias, function, or environment variable & print the definition
if alias "$1" &> /dev/null; then # alias?
alias "$1";
elif declare -f "$1" &> /dev/null; then # function?
declare -f "$1";
elif [ -n "${!1}" ]; then # environment variable? (no$)
echo "${!1}";
else
echo "No alias, function, or environment variable found for '$1'";
fi;
}
@LaptopDev
Copy link
Author

Example:

> showdef showdef
showdef () 
{ 
    if alias "$1" &> /dev/null; then
        alias "$1";
    else
        if declare -f "$1" &> /dev/null; then
            declare -f "$1";
        else
            if [ -n "${!1}" ]; then
                echo "${!1}";
            else
                echo "No alias, function, or environment variable found for '$1'";
            fi;
        fi;
    fi
}
>



> showdef c
alias c='cd'
>


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment