2014-03-04 20:25:54 +01:00
|
|
|
#compdef wd
|
|
|
|
|
2020-06-03 18:35:51 +02:00
|
|
|
zstyle ':completion::complete:wd:*:descriptions' format '%B%d%b'
|
2014-03-04 20:25:54 +01:00
|
|
|
zstyle ':completion::complete:wd:*:commands' group-name commands
|
|
|
|
zstyle ':completion::complete:wd:*:warp_points' group-name warp_points
|
|
|
|
zstyle ':completion::complete:wd::' list-grouped
|
|
|
|
|
|
|
|
zmodload zsh/mapfile
|
2014-07-15 17:42:30 +02:00
|
|
|
|
2014-03-04 20:25:54 +01:00
|
|
|
function _wd() {
|
2020-06-03 18:35:51 +02:00
|
|
|
local WD_CONFIG=${WD_CONFIG:-$HOME/.warprc}
|
2014-07-15 17:42:30 +02:00
|
|
|
local ret=1
|
2014-03-04 20:25:54 +01:00
|
|
|
|
|
|
|
local -a commands
|
|
|
|
local -a warp_points
|
2014-07-15 17:42:30 +02:00
|
|
|
|
2020-06-03 18:35:51 +02:00
|
|
|
warp_points=( "${(f)mapfile[$WD_CONFIG]//$HOME/~}" )
|
2014-03-04 20:25:54 +01:00
|
|
|
|
2017-11-01 14:03:34 +01:00
|
|
|
typeset -A points
|
|
|
|
while read -r line
|
|
|
|
do
|
|
|
|
arr=(${(s,:,)line})
|
|
|
|
name=${arr[1]}
|
2017-11-07 16:40:24 +01:00
|
|
|
target_path=${arr[2]}
|
2017-11-01 14:03:34 +01:00
|
|
|
|
|
|
|
# replace ~ from path to fix completion (#17)
|
2017-11-10 00:10:33 +01:00
|
|
|
target_path=${target_path/#\~/$HOME}
|
2017-11-01 14:03:34 +01:00
|
|
|
|
2017-11-07 16:40:24 +01:00
|
|
|
points[$name]=$target_path
|
2020-06-03 18:35:51 +02:00
|
|
|
done < $WD_CONFIG
|
2017-11-01 14:03:34 +01:00
|
|
|
|
2014-03-04 20:25:54 +01:00
|
|
|
commands=(
|
|
|
|
'add:Adds the current working directory to your warp points'
|
2024-05-21 20:48:54 +02:00
|
|
|
'addcd:Adds a directory to your warp points'
|
2014-03-04 20:25:54 +01:00
|
|
|
'add!:Overwrites existing warp point'
|
2020-06-03 18:35:51 +02:00
|
|
|
'export:Export warp points as static named directories'
|
2014-03-04 20:25:54 +01:00
|
|
|
'rm:Removes the given warp point'
|
2015-01-26 00:13:39 +01:00
|
|
|
'list:Outputs all stored warp points'
|
|
|
|
'ls:Show files from given warp point'
|
|
|
|
'path:Show path to given warp point'
|
2014-09-07 21:56:34 +02:00
|
|
|
'show:Outputs all warp points that point to the current directory or shows a specific target directory for a point'
|
2014-03-04 20:25:54 +01:00
|
|
|
'help:Show this extremely helpful text'
|
2015-01-26 00:13:39 +01:00
|
|
|
'clean:Remove points warping to nonexistent directories'
|
|
|
|
'clean!:Remove nonexistent directories without confirmation'
|
2014-03-04 20:25:54 +01:00
|
|
|
'..:Go back to last directory'
|
|
|
|
)
|
|
|
|
|
|
|
|
_arguments -C \
|
|
|
|
'1: :->first_arg' \
|
|
|
|
'2: :->second_arg' && ret=0
|
|
|
|
|
2017-11-01 14:03:34 +01:00
|
|
|
local target=$words[2]
|
|
|
|
|
2014-03-04 20:25:54 +01:00
|
|
|
case $state in
|
|
|
|
first_arg)
|
|
|
|
_describe -t warp_points "Warp points" warp_points && ret=0
|
|
|
|
_describe -t commands "Commands" commands && ret=0
|
|
|
|
;;
|
|
|
|
second_arg)
|
2017-11-01 14:03:34 +01:00
|
|
|
case $target in
|
2014-03-04 20:25:54 +01:00
|
|
|
add\!|rm)
|
|
|
|
_describe -t points "Warp points" warp_points && ret=0
|
|
|
|
;;
|
|
|
|
add)
|
|
|
|
_message 'Write the name of your warp point' && ret=0
|
|
|
|
;;
|
2024-05-21 20:48:54 +02:00
|
|
|
addcd)
|
|
|
|
_message 'Write the name of your path' && ret=0
|
|
|
|
;;
|
2014-09-07 21:56:34 +02:00
|
|
|
show)
|
|
|
|
_describe -t points "Warp points" warp_points && ret=0
|
|
|
|
;;
|
2015-01-26 00:13:39 +01:00
|
|
|
ls)
|
|
|
|
_describe -t points "Warp points" warp_points && ret=0
|
|
|
|
;;
|
|
|
|
path)
|
|
|
|
_describe -t points "Warp points" warp_points && ret=0
|
|
|
|
;;
|
2017-11-01 14:03:34 +01:00
|
|
|
*)
|
2020-06-03 18:35:51 +02:00
|
|
|
if [[ -v points[$target] ]]; then
|
|
|
|
# complete sub directories from the warp point
|
|
|
|
_path_files -W "(${points[$target]})" -/ && ret=0
|
|
|
|
fi
|
2024-03-26 09:55:16 +01:00
|
|
|
|
2020-06-03 18:35:51 +02:00
|
|
|
# don't complete anything if warp point is not valid
|
2017-11-01 14:03:34 +01:00
|
|
|
;;
|
2014-03-04 20:25:54 +01:00
|
|
|
esac
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
return $ret
|
2013-11-26 00:46:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
_wd "$@"
|
2014-03-04 20:25:54 +01:00
|
|
|
|
|
|
|
# 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
|