Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the compopt equivalent in zsh that modifies the current completion options?

I am writing an auto completion script for zsh that I want to enable nospace on certain conditions. The bash equivalent script would look like this

_my_completion(){
  if something; then
    compopt -o nospace
  fi
}

complete -F _my_completion <exec>

How do I achieve the same goal in zsh?

like image 533
剑走偏风 Avatar asked Nov 08 '22 12:11

剑走偏风


1 Answers

The similar effect can be done using -S '' as compadd argument, as you can see:

_my_completion(){
  # Here you can access ${words[@]}, $BUFFER, $CURSOR, $NAME, $CURRENT...
  if something; then
    completions_array=(foo bar baz)

    # `-S ''` is the equivalent of `compopt -o nospace`
    compadd -S '' -a completions_array
  fi
}

compdef _my_completion <exec>

If you're familiar with bash completions, you can see how zsh completions compare in this script that loads the bash completions in ZSH.

like image 174
Treviño Avatar answered Nov 12 '22 20:11

Treviño