-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzle-fzf.plugin.zsh
51 lines (45 loc) · 1.29 KB
/
zle-fzf.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
#!/bin/zsh
function _fuzzy-insert-command {
local choice
choice=$(type -m '*' | fzf --height=40% | awk '{print $1}')
zle -U "$choice"
zle reset-prompt
}
function _fuzzy-insert-filename {
local choice
choice=$(find | fzf --height=40%)
zle -U "$choice"
zle reset-prompt
}
function _fuzzy-insert-variable {
local choice
choice="$"$(typeset | fzf --height=40% | awk -F= '{print $1}')
zle -U "$choice"
zle reset-prompt
}
function _fuzzy-insert-recent-dir {
local choice
if which _z &> /dev/null; then
# if you use z to jump between directories
choice=$(_z -l 2>&1 \
| tac \
| grep "/.*" -o \
| fzf --height=40%)
elif which autojump &> /dev/null; then
# if you use autojump
choice=$(autojump -s \
| sed -E '/^___/q;s/[0-9]*\.[0-9]*:[[:space:]]*//;' \
| head -n-1 \
| fzf --height=40%)
fi
zle -U "$choice"
zle reset-prompt
}
zle -N _fuzzy-insert-command
zle -N _fuzzy-insert-filename
zle -N _fuzzy-insert-variable
zle -N _fuzzy-insert-recent-dir
bindkey '^[x' _fuzzy-insert-command
bindkey '^[f' _fuzzy-insert-filename
bindkey '^[v' _fuzzy-insert-variable
bindkey '^[d' _fuzzy-insert-recent-dir