-
Notifications
You must be signed in to change notification settings - Fork 3
/
_cd-bookmark
85 lines (75 loc) · 2.57 KB
/
_cd-bookmark
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#compdef cd-bookmark
# ------------------------------------------------------------------------------
# Copyright (c) 2014 Hideaki Miyake
# Licensed under the MIT License (MIT)
# ------------------------------------------------------------------------------
# Description
# -----------
#
# Completion script for cd-bookmark (https://github.com/mollifier/cd-bookmark)
#
# ------------------------------------------------------------------------------
# Authors
# -------
#
# * Hideaki Miyake (https://github.com/mollifier)
#
# ------------------------------------------------------------------------------
declare -a opts args
args=(
'(:)-a[add current directory to bookmark]:new_bookmark_id:_cd-bookmark_current_directory_name'
'-c[change directory which is identified by BOOKMARK_ID]:bookmark_id:->bookmark_id_or_path'
'-l[list bookmark]'
'-e[edit bookmark file]'
'-p[display bookmark real path for BOOKMARK_ID]:bookmark_id:_cd-bookmark_bookmark_id'
'-h[display this help and exit]'
'1:bookmark_id:->bookmark_id_or_path'
)
local curcontext=$curcontext state line ret=1
declare -A opt_args
# show current directory name
(( $+functions[_cd-bookmark_current_directory_name] )) ||
_cd-bookmark_current_directory_name() {
local -a directory_name
directory_name=( "${PWD:t}" )
_describe -t current_directory_name "current directory name" directory_name
}
# show bookmark id list
(( $+functions[_cd-bookmark_bookmark_id] )) ||
_cd-bookmark_bookmark_id() {
local -a _bookmark_id_list
_bookmark_id_list=( ${(@f)"$(_call_program cd-bookmark-list cd-bookmark -l | cut -d '|' -f 1 | sort -n)"} )
_describe -t bookmark_id "bookmark id" _bookmark_id_list
}
(( $+functions[_cd-bookmark_bookmark_id_compset] )) ||
_cd-bookmark_bookmark_id_compset() {
local -a _bookmark_id_list
_bookmark_id_list=( ${(@f)"$(_call_program cd-bookmark-list cd-bookmark -l | cut -d '|' -f 1 | sort -n)"} )
compadd -S '/' -q -a _bookmark_id_list
}
# expand bookmark_id to real path and complete subdirectory
(( $+functions[_cd-bookmark_expand_bookmark_id] )) ||
_cd-bookmark_expand_bookmark_id() {
local bookmark_id="${IPREFIX%/}"
local real_path="$(_call_program cd-bookmark-expand-id cd-bookmark -p "$bookmark_id")"
_path_files -W "$real_path" -/
}
_arguments -C $opts \
$args && ret=0
case "$state" in
bookmark_id_or_path)
if compset -P 1 '*/'; then
_cd-bookmark_expand_bookmark_id
else
_cd-bookmark_bookmark_id_compset
fi
;;
esac
return $ret
# 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