I do have a simple function (in "reality" it is "a bit" more complex - just for illustration)
cat test.sh
_foocomplete(){
local list="abc\ndef\nghi"
local cur=${COMP_WORDS[COMP_CWORD]}
COMPREPLY=( $(echo -e ${list} | grep "${cur}") )
}
foo(){
echo "$1"
}
complete -F _foocomplete foo
Using this in bash, gives me
~ ❯ ps -o cmd= $$
bash
~ ❯ type foo
bash: type: foo: not found
~ ❯ source test.sh
~ ❯ foo <TAB>
abc def ghi
~ ❯ foo a<TAB>
abc
~ ❯ foo e<TAB>
def
Using it in zsh, is very similar
~ ❯ ps -o cmd= $$
-zsh
~ ❯ type -f foo
foo not found
~ ❯ source test.sh
~ ❯ foo <TAB>
abc def ghi
~ ❯ foo a<TAB>
abc
BUT that
~ ❯ foo e<TAB>
does not work (as in: does not, like in bash, give me def as option).
Is there - besides rewriting and using compdef - an "easy" explanation (and "fix")?
This is with no .zshrc (but also with e.g. Oh My Zsh)
As reply to autocomplete bash vs. zsh
cat test2.sh
foo(){
local list="abc\ndef\nghi"
echo -e ${list} | grep e
}
foo
~ ❯ /bin/zsh test2.sh
def
~ ❯ /bin/bash test2.sh
def
Thank you in advance