showdef () {
local file=
if [[ $1 == -f ]]
then
file=$2
shift 2
fi
if [[ -n $file ]]
then
(
shopt -s expand_aliases
source "$file" 2> /dev/null
showdef "$1"
)
return
fi
if alias "$1" &> /dev/null
then
alias "$1"
elif declare -f "$1" &> /dev/null
then
declare -f "$1"
elif [[ -n ${!1} ]]
then
echo "${!1}"
else
echo "No alias, function, or environment variable found for '$1'"
fi
}
This looks up the definition of a shell name — alias, function, or environment variable — and prints it.
with -f [.bashrc (for example)] it sources the given file in a subshell before running the lookup in that subshell.
showdef () { local file= if [[ $1 == -f ]] then file=$2 shift 2 fi if [[ -n $file ]] then ( shopt -s expand_aliases source "$file" 2> /dev/null showdef "$1" ) return fi if alias "$1" &> /dev/null then alias "$1" elif declare -f "$1" &> /dev/null then declare -f "$1" elif [[ -n ${!1} ]] then echo "${!1}" else echo "No alias, function, or environment variable found for '$1'" fi }
This looks up the definition of a shell name — alias, function, or environment variable — and prints it. with -f [.bashrc (for example)] it sources the given file in a subshell before running the lookup in that subshell.
a nice project, but for many users fish shell provides the same with abbreviations, smart autocompletion, and fuzzy history search all baked right in