How to remove extra space from zsh autocomplete function?

I use compctl -K _my_cpl ls to bind my automatic function to the ls . The function returns a list of names from the index file.

However, zsh always adds a space after each completion. If I want to automatically fill in several level directories, I have to remove the space every time. Is there a way to remove extra space, like the -o nospace option in bash full command?

I tested the zstyle ':completion:*' add-space false command and it does not work. Thanks.

 _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 
+6
source share
1 answer
 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 does not allow you to specify a different suffix for directories and regular files. If you want this, I think you need to switch to the “new” termination system and make separate compadd calls with different -S arguments.

+2
source

Source: https://habr.com/ru/post/903031/


All Articles