forked from andrewferrier/fzf-z
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fzf-z.plugin.zsh
42 lines (36 loc) · 1.01 KB
/
fzf-z.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
#!/usr/bin/env zsh
#
# Based on https://github.com/junegunn/fzf/blob/master/shell/key-bindings.zsh
# (MIT licensed, as of 2016-05-05).
FZFZ_SCRIPT_PATH=${0:a:h}
__fzfz() {
$FZFZ_SCRIPT_PATH/fzfz | while read item; do
printf '%q ' "${item/\~/$HOME}"
done
echo
}
fzfz-dir-widget() {
local shouldAccept=$(should-accept-line)
LBUFFER="${LBUFFER}$(__fzfz)"
local ret=$?
zle redisplay
typeset -f zle-line-init >/dev/null && zle zle-line-init
if [[ $ret -eq 0 && -n "$BUFFER" && -n "$shouldAccept" ]]; then
zle .accept-line
fi
return $ret
}
# Accept the line if the buffer was empty before invoking the file widget, and
# the `auto_cd` option is set.
should-accept-line() {
if [[ ${#${(z)BUFFER}} -eq 0 && -o auto_cd ]]; then
echo "true";
fi
}
zle -N fzfz-dir-widget
bindkey -M viins -r '^G'
bindkey -M vicmd -r '^G'
bindkey -M emacs -r '^G'
bindkey -M viins '^G' fzfz-dir-widget
bindkey -M vicmd '^G' fzfz-dir-widget
bindkey -M emacs '^G' fzfz-dir-widget