parent
6b3c953775
commit
d41ac7fe3e
3 changed files with 102 additions and 87 deletions
@ -1,48 +1,68 @@ |
|||||||
#compdef wd.sh |
#compdef wd |
||||||
|
|
||||||
zstyle ":completion:*:descriptions" format "%B%d%b" |
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 |
||||||
|
|
||||||
CONFIG=$HOME/.warprc |
# Call `_wd()` when when trying to complete the command `wd` |
||||||
|
|
||||||
local -a main_commands |
zmodload zsh/mapfile |
||||||
main_commands=( |
function _wd() { |
||||||
add:'Adds the current working directory to your warp points' |
local ret=1 |
||||||
#add'\!':'Overwrites existing warp point' # TODO: Fix |
local CONFIG=$HOME/.warprc |
||||||
rm:'Removes the given warp point' |
|
||||||
ls:'Outputs all stored warp points' |
# Stolen from |
||||||
show:'Outputs warp points to current directory' |
# http://stackoverflow.com/questions/9000698/completion-when-program-has-sub-commands |
||||||
) |
|
||||||
|
|
||||||
local -a points |
# local curcontext="$curcontext" state line |
||||||
while read line |
# typeset -A opt_args |
||||||
do |
|
||||||
points+=$(awk "{ gsub(/\/Users\/$USER|\/home\/$USER/,\"~\"); print }" <<< $line) |
|
||||||
done < $CONFIG |
|
||||||
|
|
||||||
_wd() |
local -a commands |
||||||
{ |
local -a warp_points |
||||||
# init variables |
warp_points=( "${(f)mapfile[$CONFIG]}" ) |
||||||
local curcontext="$curcontext" state line |
# LIST="${mapfile[$FNAME]}" # Not required unless stuff uses it |
||||||
typeset -A opt_args |
|
||||||
|
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' |
||||||
|
) |
||||||
|
|
||||||
# init state |
_arguments -C \ |
||||||
_arguments \ |
'1: :->first_arg' \ |
||||||
'1: :->command' \ |
'2: :->second_arg' && ret=0 |
||||||
'2: :->argument' |
|
||||||
|
|
||||||
case $state in |
case $state in |
||||||
command) |
first_arg) |
||||||
compadd "$@" add rm ls show |
_describe -t warp_points "Warp points" warp_points && ret=0 |
||||||
_describe -t warp-points 'Warp points:' points && ret=0 |
_describe -t commands "Commands" commands && ret=0 |
||||||
;; |
;; |
||||||
argument) |
second_arg) |
||||||
case $words[2] in |
case $words[2] in |
||||||
rm|add!) |
add\!|rm) |
||||||
_describe -t warp-points 'warp points' points && ret=0 |
_describe -t points "Warp points" warp_points && ret=0 |
||||||
|
;; |
||||||
|
add) |
||||||
|
_message 'Write the name of your warp point' && ret=0 |
||||||
;; |
;; |
||||||
*) |
|
||||||
esac |
esac |
||||||
|
;; |
||||||
esac |
esac |
||||||
|
|
||||||
|
return $ret |
||||||
} |
} |
||||||
|
|
||||||
_wd "$@" |
_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 |
||||||
|
|||||||
Loading…
Reference in new issue