Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove an additional space from zsh auto complete function?

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
like image 532
leo Avatar asked Dec 04 '11 02:12

leo


1 Answers

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.

like image 117
Gilles 'SO- stop being evil' Avatar answered Oct 04 '22 20:10

Gilles 'SO- stop being evil'