I'm no expert at this, still learning, but after finding this question and its answer because I wanted the same, I wrote the following (based on "The Archetypal Paul's declare" answer) to give me ultimately what I was after: a formatted list of both aliases and functions:
function functionaliaslist() {
echo
echo -e "\033[1;4;32m""Functions:""\033[0;34m"
declare -F | awk {'print $3'}
echo
echo -e "\033[1;4;32m""Aliases:""\033[0;34m"
alias | awk {'print $2'} | awk -F= {'print $1'}
echo
echo -e "\033[0m"
}
That was before I saw Lri's answer, and so extrapolating from that, I replace the declare
and alias
lines with appropriate compgen
commands instead, to get:
function functionaliaslist() {
echo
echo -e "\033[1;4;32m""Functions:""\033[0;34m"
compgen -A function
echo
echo -e "\033[1;4;32m""Aliases:""\033[0;34m"
compgen -A alias
echo
echo -e "\033[0m"
}
Woks a treat for what I wanted. Sharing in case it helps anyone else.
There are a multitude of other "actions" available to compgen -A [action]
(and other options for compgen
of course). I found a good write-up here which also includes a link to the man page (because man compgen
doesn't work in some cases).