#StackBounty: #zsh Why does a value '-' (hyphen) in "tag-order" style prevent matching of the "executables"…

Bounty: 150

With the code below, everything works as expected:

  • When I write c and hit the TAB key, I get the appropriate completions in correct order. (Image)
  • When I write ./ and hit the TAB key, I get the completion for the executables tag. (Image)

# Always use menu selection when using unambiguous completions.
zstyle ':completion:*:*:*:*:*' menu 'select'

# Show only completions.
zstyle ':completion:*:*:*:*:*' completer _complete

# Group name becomes the name of the matching tag.
zstyle ':completion:*:*:*:*:*' group-name ''

# Configure the order of tag matching as well as their descriptions.
zstyle -e ':completion:*:*:-command-:*:*' tag-order '
    reply=(
           "executables:Executables:Executables
            builtins:Builtins:Builtins
            commands:Commands:Commands
            aliases:Aliases:Aliases
            functions:Functions:Functions
            parameters:Variables:Variables
            reserved-words:Keywords:Keywords"
          )
'

# Configure the order in which completion groups will be shown.
zstyle ':completion:*:*:-command-:*:*' group-order 'Executables' 'Builtins' 'Commands' 'Aliases' 'Functions' 'Variables' 'Keywords'

# Configure the format for each group/tag description.
zstyle ':completion:*:*:*:*:descriptions' format '%{[0;38;2;0;0;0;48;2;200;150;0m%} %d %{[0;38;2;200;150;0;48;2;0;0;0m%}%{[0m%}'

# Initialize completion system.
autoload -Uz compinit && compinit

However if the tags that I’ve specified do not produce any completion, other tags will be tried as well.
I don’t like this behavior and want to limit the search only to tags that I have explicitly specified.

The manual for the tag-order style suggests a simple solution:

– If any value consists of only a hyphen, then only the tags specified in the other values are generated. Normally all tags not explicitly selected are tried last if the specified tags fail to generate any matches. This means that a single value consisting only of a single hyphen turns off completion.

Applying the solution:

# Configure the order of tag matching as well as their descriptions.
zstyle -e ':completion:*:*:-command-:*:*' tag-order '
    reply=(
           "executables:Executables:Executables
            builtins:Builtins:Builtins
            commands:Commands:Commands
            aliases:Aliases:Aliases
            functions:Functions:Functions
            parameters:Variables:Variables
            reserved-words:Keywords:Keywords"
           "-"
          )
'

Current behavior is:

  • When I write c and hit the TAB key, I get the appropriate completions in correct order. (Image)
  • When I write ./ and hit the TAB key, I get nothing. (Image)

Why is now only executables tag not working?

How can I fix it and get the desired behavior?


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.