I am in the process of replicating my development environment under Ubuntu from Macos. A good deal of which consists of porting some utility zsh scripts *from one machine to the other*.
One recurring hurdle has been getting
compgen
to work. I've researched posts like [Bash completion does not work in ZSH/Oh-My-ZSH because COMP_WORDS is not an array](https://stackoverflow.com/questions/69675174/bash-completion-does-not-work-in-zsh-oh-my-zsh-because-comp-words-is-not-an-arra)
Bottom line: so far, on Linux zsh, I am stuck with "compgen command not found".
I did use locate
to find a compgen
somewhere under bash completions, but calling it from zsh did not work. Yes, compgen
works, from bash.
Back on my mac, where compgen
does work, I idly did a which compgen
under zsh, which returned what looks like a function definition rather than a path.
which compgen
:
(only first 10 lines copied to give you an idea)
`
compgen () {
local opts prefix suffix job OPTARG OPTIND ret=1
local -a name res results jids
local -A shortopts
emulate -L sh
setopt kshglob noshglob braceexpand nokshautoload
shortopts=(a alias b builtin c command d directory e export f file g group j job k keyword u user v variable)
while getopts "o:A:G:C:F:P:S:W:X:abcdefgjkuv" name
do
case $name in
....
`
Meanwhile, under **bash**, which compgen
returns nothing, presumably because it is a builtin.
So where does compgen
under **zsh** come from? Is it computed through the completion initialization in my **~/.zshrc** ? quite possibly bashcompinit
?:
(note: below is from the macos ~/.zshrc, where compgen works)
`
# The following lines were added by compinstall
zstyle :compinstall filename '/Users/me/.zshrc'
autoload -Uz compinit
compinit
# End of lines added by compinstallx
autoload -Uz bashcompinit
bashcompinit
#stop completions from $PATH on source, as per https://stackoverflow.com/a/72710684
unset '_comps[source]'
`
Asked by JL Peyret
(115 rep)
Jun 17, 2024, 12:19 AM
Last activity: Jun 17, 2024, 05:00 PM
Last activity: Jun 17, 2024, 05:00 PM