-
Notifications
You must be signed in to change notification settings - Fork 8
/
.fzy.zsh
54 lines (51 loc) · 1.11 KB
/
.fzy.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
#
# fzy shell integration
#
# Adapted from fzf (https://github.com/junegunn/fzf).
#
# Copyright (c) 2016 Junegunn Choi
# Copyright (c) 2016 Alexis Sellier
#
if [[ $- != *i* ]]; then
return
fi
__fzy_fsel () {
setopt localoptions pipefail 2> /dev/null
command rg --files -u . * | fzy | while read -r item; do
echo -n "${(q)item}"
done
local ret=$?
echo
return $ret
}
fzy-file-widget () {
LBUFFER="${LBUFFER}$(__fzy_fsel)"
local ret=$?
zle redisplay
if [[ $ret == 0 ]]; then
zle accept-line "$LBUFFER"
ret=$?
fi
typeset -f zle-line-init >/dev/null && zle zle-line-init
return $ret
}
zle -N fzy-file-widget
bindkey '^P' fzy-file-widget
fzy-history-widget () {
local selected num
setopt localoptions noglobsubst pipefail 2> /dev/null
selected=( $(fc -l -r 1 | fzy -q "${LBUFFER//$/\\$}") )
local ret=$?
if [[ -n ${selected} ]]; then
num=${selected[1]}
if [[ -n ${num} ]]; then
zle vi-fetch-history -n ${num}
zle accept-line "$LBUFFER"
fi
fi
zle redisplay
typeset -f zle-line-init >/dev/null && zle zle-line-init
return $ret
}
zle -N fzy-history-widget
bindkey '^H' fzy-history-widget