Shell – List names of aliases, functions and variables in zsh

shellzsh

I need a way to list the names (without the body/content/value) of aliases, functions, variables, arrays in zsh. Optimally it should behave like compgen:

compgen -a # will list all the aliases you could run.
compgen -A function # will list all the functions you could run.
compgen -A variable # will list all the variables defined.

Background

I need this to develop env_parallel.zsh: https://www.gnu.org/software/parallel/env_parallel.html

Best Answer

Aliases and functions are contained in aliases and functions, and one merely needs to print the keys of such. "Variables and arrays" is trickier; parameters may suffice?

print -rl -- ${(k)aliases} ${(k)functions} ${(k)parameters}

(You may also need builtins, commands, and perhaps other things listed from print -l ${(k) and then mashing tab, assuming completion is enabled.)

Related Question