]> src.twobees.de Git - dotfiles.git/blob - stow/oh-my-zsh/.oh-my-zsh/plugins/wd/_wd.sh
8d5cf15a2633fcaa2475f5fd2ba18350e7f89d74
[dotfiles.git] / stow / oh-my-zsh / .oh-my-zsh / plugins / wd / _wd.sh
1 #compdef wd
2
3 zstyle ':completion::complete:wd:*:descriptions' format '%B%d%b'
4 zstyle ':completion::complete:wd:*:commands' group-name commands
5 zstyle ':completion::complete:wd:*:warp_points' group-name warp_points
6 zstyle ':completion::complete:wd::' list-grouped
7
8 zmodload zsh/mapfile
9
10 function _wd() {
11   local WD_CONFIG=${WD_CONFIG:-$HOME/.warprc}
12   local ret=1
13
14   local -a commands
15   local -a warp_points
16
17   warp_points=( "${(f)mapfile[$WD_CONFIG]//$HOME/~}" )
18
19   typeset -A points
20   while read -r line
21   do
22     arr=(${(s,:,)line})
23     name=${arr[1]}
24     target_path=${arr[2]}
25
26     # replace ~ from path to fix completion (#17)
27     target_path=${target_path/#\~/$HOME}
28
29     points[$name]=$target_path
30   done < $WD_CONFIG
31
32   commands=(
33     'add:Adds the current working directory to your warp points'
34     'add!:Overwrites existing warp point'
35     'export:Export warp points as static named directories'
36     'rm:Removes the given warp point'
37     'list:Outputs all stored warp points'
38     'ls:Show files from given warp point'
39     'path:Show path to given warp point'
40     'show:Outputs all warp points that point to the current directory or shows a specific target directory for a point'
41     'help:Show this extremely helpful text'
42     'clean:Remove points warping to nonexistent directories'
43     'clean!:Remove nonexistent directories without confirmation'
44     '..:Go back to last directory'
45   )
46
47   _arguments -C \
48     '1: :->first_arg' \
49     '2: :->second_arg' && ret=0
50
51   local target=$words[2]
52
53   case $state in
54     first_arg)
55       _describe -t warp_points "Warp points" warp_points && ret=0
56       _describe -t commands "Commands" commands && ret=0
57       ;;
58     second_arg)
59       case $target in
60         add\!|rm)
61           _describe -t points "Warp points" warp_points && ret=0
62           ;;
63         add)
64           _message 'Write the name of your warp point' && ret=0
65           ;;
66         show)
67           _describe -t points "Warp points" warp_points && ret=0
68           ;;
69         ls)
70           _describe -t points "Warp points" warp_points && ret=0
71           ;;
72         path)
73           _describe -t points "Warp points" warp_points && ret=0
74           ;;
75         *)
76           if [[ -v points[$target] ]]; then
77             # complete sub directories from the warp point
78             _path_files -W "(${points[$target]})" -/ && ret=0
79           fi
80           
81           # don't complete anything if warp point is not valid
82           ;;
83       esac
84       ;;
85   esac
86
87   return $ret
88 }
89
90 _wd "$@"
91
92 # Local Variables:
93 # mode: Shell-Script
94 # sh-indentation: 2
95 # indent-tabs-mode: nil
96 # sh-basic-offset: 2
97 # End:
98 # vim: ft=zsh sw=2 ts=2 et