diff options
author | Markus Faerevaag <mf@bitblueprint.com> | 2014-03-04 20:25:54 +0100 |
---|---|---|
committer | Markus Faerevaag <mf@bitblueprint.com> | 2014-03-04 20:25:54 +0100 |
commit | d41ac7fe3e52783054610c2cc57bbbfcdb2202b0 (patch) | |
tree | ad9574b90c6240ce653792dd58d80e2ea2f8f935 /plugins/wd/_wd.sh | |
parent | 6b3c9537754b4a2180648258341ae2d7ca203d1e (diff) | |
download | zsh-d41ac7fe3e52783054610c2cc57bbbfcdb2202b0.tar.gz zsh-d41ac7fe3e52783054610c2cc57bbbfcdb2202b0.tar.bz2 zsh-d41ac7fe3e52783054610c2cc57bbbfcdb2202b0.zip |
Updated wd plugin to v0.3.0
Diffstat (limited to 'plugins/wd/_wd.sh')
-rw-r--r-- | plugins/wd/_wd.sh | 110 |
1 files changed, 65 insertions, 45 deletions
diff --git a/plugins/wd/_wd.sh b/plugins/wd/_wd.sh index 950564435..29df63520 100644 --- a/plugins/wd/_wd.sh +++ b/plugins/wd/_wd.sh @@ -1,48 +1,68 @@ -#compdef wd.sh - -zstyle ":completion:*:descriptions" format "%B%d%b" - -CONFIG=$HOME/.warprc - -local -a main_commands -main_commands=( - add:'Adds the current working directory to your warp points' - #add'\!':'Overwrites existing warp point' # TODO: Fix - rm:'Removes the given warp point' - ls:'Outputs all stored warp points' - show:'Outputs warp points to current directory' -) - -local -a points -while read line -do - points+=$(awk "{ gsub(/\/Users\/$USER|\/home\/$USER/,\"~\"); print }" <<< $line) -done < $CONFIG - -_wd() -{ - # init variables - local curcontext="$curcontext" state line - typeset -A opt_args - - # init state - _arguments \ - '1: :->command' \ - '2: :->argument' - - case $state in - command) - compadd "$@" add rm ls show - _describe -t warp-points 'Warp points:' points && ret=0 - ;; - argument) - case $words[2] in - rm|add!) - _describe -t warp-points 'warp points' points && ret=0 - ;; - *) - esac - esac +#compdef wd + +zstyle ':completion:*:descriptions' format '%B%d%b' +zstyle ':completion::complete:wd:*:commands' group-name commands +zstyle ':completion::complete:wd:*:warp_points' group-name warp_points +zstyle ':completion::complete:wd::' list-grouped + +# Call `_wd()` when when trying to complete the command `wd` + +zmodload zsh/mapfile +function _wd() { + local ret=1 + local CONFIG=$HOME/.warprc + + # Stolen from + # http://stackoverflow.com/questions/9000698/completion-when-program-has-sub-commands + + # local curcontext="$curcontext" state line + # typeset -A opt_args + + local -a commands + local -a warp_points + warp_points=( "${(f)mapfile[$CONFIG]}" ) + # LIST="${mapfile[$FNAME]}" # Not required unless stuff uses it + + commands=( + 'add:Adds the current working directory to your warp points' + 'add!:Overwrites existing warp point' + 'rm:Removes the given warp point' + 'ls:Outputs all stored warp points' + 'show:Outputs all warp points that point to the current directory' + 'help:Show this extremely helpful text' + '..:Go back to last directory' + ) + + _arguments -C \ + '1: :->first_arg' \ + '2: :->second_arg' && ret=0 + + case $state in + first_arg) + _describe -t warp_points "Warp points" warp_points && ret=0 + _describe -t commands "Commands" commands && ret=0 + ;; + second_arg) + case $words[2] in + add\!|rm) + _describe -t points "Warp points" warp_points && ret=0 + ;; + add) + _message 'Write the name of your warp point' && ret=0 + ;; + esac + ;; + esac + + return $ret } _wd "$@" + +# Local Variables: +# mode: Shell-Script +# sh-indentation: 2 +# indent-tabs-mode: nil +# sh-basic-offset: 2 +# End: +# vim: ft=zsh sw=2 ts=2 et |