I use compctl -K _my_cpl ls
to hook my auto complete function to ls
command. The function returns a list of names from an index file.
However, zsh always adds a space after each completion. If I want to auto complete multiple level directory, I have to remove a space every time. Is there a way to remove additional space just like the -o nospace
option in bash complete command?
I tested zstyle ':completion:*' add-space false
command and it does not work. Thank you.
_my_cpl() {
local cur last opts
# current word in command line.
read -cA cur
last=$cur[-1]
# grep all directories and file names under current directory level.
opts=`egrep "${last}[^/]*[$|/]*" ~/index -o |uniq`
reply=($=opts)
}
compctl -K _my_cpl ls
compctl -K _my_cpl -S '' ls
This answers the question you asked, but it may not be flexible enough for what you want to do. In particular, this approach doesn't let you specify a different suffix for directories and regular files. If you want that, I think you need to switch to the “new” completion system and make separate calls to compadd
with different -S
arguments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With