-
Notifications
You must be signed in to change notification settings - Fork 3
/
plugin.zsh
51 lines (40 loc) · 1.08 KB
/
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
favorite-directories:cd() {
# eval prevents IFS to modify in global scope
IFS=$'\n' eval 'local sources=($(favorite-directories:get))'
local name
local maxdepth
local mindepth
local dir
local target_dir=$({
for source in "${sources[@]}"; do
read -r name maxdepth dir mindepth <<< "$source"
find "$dir" \
-maxdepth "${maxdepth:-1}" \
-mindepth "${mindepth:-1}" \
-type d -printf "$name: %P\\n" \
2>/dev/null
done
} | fzf-tmux)
local token=${target_dir//:*/}
local target_dir=${target_dir//*: /}
for source in "${sources[@]}"; do
read -r name maxdepth dir mindepth <<< "$source"
if [ "$name" = "$token" ]; then
eval cd "$dir/$target_dir"
break
fi
done
unset sources
unset maxdepth
unset dir
unset target_dir
unset token
for func in "${precmd_functions[@]}"; do
"$func"
done
zle reset-prompt
}
favorite-directories:get() {
:
}
zle -N favorite-directories:cd