_wd.sh 1.66 KB
Newer Older
Markus Faerevaag's avatar
Markus Faerevaag committed
1
2
3
4
5
6
7
8
#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

zmodload zsh/mapfile
9

Markus Faerevaag's avatar
Markus Faerevaag committed
10
11
function _wd() {
  local CONFIG=$HOME/.warprc
12
  local ret=1
Markus Faerevaag's avatar
Markus Faerevaag committed
13
14
15

  local -a commands
  local -a warp_points
16
17

  warp_points=( "${(f)mapfile[$CONFIG]//$HOME/~}" )
Markus Faerevaag's avatar
Markus Faerevaag committed
18
19
20
21
22
23

  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'
24
25
    'show:Outputs all warp points that point to the current directory or shows a specific target directory for a point'
    'show:Outputs all warp points that point to the current directory or shows a specific target directory for a point'
Markus Faerevaag's avatar
Markus Faerevaag committed
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
    '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
          ;;
47
48
49
        show)
          _describe -t points "Warp points" warp_points && ret=0
          ;;
Markus Faerevaag's avatar
Markus Faerevaag committed
50
51
52
53
54
      esac
      ;;
  esac

  return $ret
55
56
57
}

_wd "$@"
Markus Faerevaag's avatar
Markus Faerevaag committed
58
59
60
61
62
63
64
65

# 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