Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

zsh: rework ZSH completion #30

Open
wants to merge 1 commit into from

2 participants

@vincentbernat

The completion for ZSH is upgraded to the new ZSH completion
system. To work, the file should be placed somewhere in ZSH fpath to
be autoloaded when needed and named _sub.

There are other embedded misc changes:

  • $CURRENT indicate which word is being autocompleted.
  • In ZSH, automatic word splitting is disabled in completion. There is no need to quote words.

The completion also handles plugins that are able to complete
args. However, most plugins don't and will complete with a subcommand
instead. I don't think there is an universal solution for this.

I am no ZSH wizard. Take this commit with care (works for me).

@vincentbernat vincentbernat zsh: rework ZSH completion
The completion for ZSH is upgraded to the new ZSH completion
system. To work, the file should be placed somewhere in ZSH fpath to
be autoloaded when needed and named `_sub`.

There are other embedded misc changes:
 - `$CURRENT` indicate which word is being autocompleted.
 - In ZSH, automatic word splitting is disabled in completion. There
   is no need to quote words.
4976f83
@mislav

Looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 19, 2012
  1. @vincentbernat

    zsh: rework ZSH completion

    vincentbernat authored
    The completion for ZSH is upgraded to the new ZSH completion
    system. To work, the file should be placed somewhere in ZSH fpath to
    be autoloaded when needed and named `_sub`.
    
    There are other embedded misc changes:
     - `$CURRENT` indicate which word is being autocompleted.
     - In ZSH, automatic word splitting is disabled in completion. There
       is no need to quote words.
This page is out of date. Refresh to see the latest.
Showing with 20 additions and 17 deletions.
  1. +20 −17 completions/sub.zsh
View
37 completions/sub.zsh
@@ -1,19 +1,22 @@
-if [[ ! -o interactive ]]; then
- return
-fi
+#compdef sub
-compctl -K _sub sub
+# This completion file should be linked to a directory in ZSH fpath
+# and named `_sub`.
-_sub() {
- local word words completions
- read -cA words
- word="${words[2]}"
-
- if [ "${#words}" -eq 2 ]; then
- completions="$(sub commands)"
- else
- completions="$(sub completions "${word}")"
- fi
-
- reply=("${(ps:\n:)completions}")
-}
+case $CURRENT in
+ 2)
+ local cmds
+ local -a commands
+ cmds=$(sub commands)
+ commands=(${(ps:\n:)cmds})
+ _wanted command expl "sub command" compadd -a commands
+ ;;
+ *)
+ local cmd subcmds
+ local -a commands
+ cmd=${words[2]}
+ subcmds=$(sub completions ${words[2,$(($CURRENT - 1))]})
+ commands=(${(ps:\n:)subcmds})
+ _wanted subcommand expl "sub $cmd subcommand" compadd -a commands
+ ;;
+esac
Something went wrong with that request. Please try again.