-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdirnav.plugin.zsh
102 lines (91 loc) · 1.99 KB
/
dirnav.plugin.zsh
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env zsh
source ${0:A:h}/dirnav.sh
function _dirnav_compl_zsh_bd() {
local _dirs=(${(s:/:)$(dirname "$PWD")})
_dirs=(${(Oa)_dirs})
reply=()
for _dir in $_dirs
do
case "$_dir" in
*$1* )
reply=($reply "$_dir")
;;
esac
done
}
compctl -k "()" -x 'm[1,2]' -V directories -U -K _dirnav_compl_zsh_bd -- _dirnav_cmd_bd
function _dirnav_compl_zsh_jd_marks() {
_dirnav_opt_global=0
_dirnav_opt_local=0
_dirnav_opt_session=0
_dirnav_opt_delete=0
_dirnav_internal_nearest=0
_cmdline=($words '-N')
_cmd=("_dirnav_cmd_jd")
while getopts ":glsd" _opt ${_cmdline:|_cmd}
do
case "$_opt" in
g )
_dirnav_opt_global=1
;;
l )
_dirnav_opt_local=1
;;
s )
_dirnav_opt_session=1
;;
d )
_dirnav_opt_delete=1
;;
\? )
;;
: )
;;
esac
done
local _dirnav_opt_mark_name="$words[$CURRENT]"
if [ "$_dirnav_opt_global" -eq 0 ] \
&& [ "$_dirnav_opt_local" -eq 0 ] \
&& [ "$_dirnav_opt_session" -eq 0 ]
then
if [ "$_dirnav_opt_delete" -eq 1 ]
then
_dirnav_opt_session=1
_dirnav_internal_nearest=1
else
_dirnav_opt_global=1
_dirnav_opt_local=1
_dirnav_opt_session=1
fi
fi
local _stores=$(_dirnav_util_store_find)
_ifs_bak="$IFS"
IFS=$(printf '\t')
for _store in $(echo $_stores)
do
local _marks="$(awk -F '\t' "/^$_opt_mark_name/ { print \$1 }" "$_store")"
IFS=$'\n'
for _mark in $(echo $_marks)
do
compadd "$@" "$_mark"
done
IFS=$(printf '\t')
done
IFS="$_ifs_bak"
}
function _dirnav_compl_zsh_jd() {
_arguments -s -w -A '-*' : \
'(-c)-g[use global store]' \
'(-c)-l[use local store]' \
'(-c)-s[use session store]' \
'(-g -l -s -d -L -f -F 1 2)-c[create local store]:path:_path_files -\/' \
'(-c -L -f -F 2)-d[delete mark]' \
'(-c -d -f -F 1 2)-L[list marks]' \
'(-c -d -L)-f[force create mark]' \
'(-c -d -L)-F[create mark as-is]' \
'-n[dryrun]' \
'-v[verbose]' \
'1:mark:_dirnav_compl_zsh_jd_marks' \
'2:target:_path_files -\/' \
}
compdef _dirnav_compl_zsh_jd _dirnav_cmd_jd