-
Notifications
You must be signed in to change notification settings - Fork 3
/
fzf-finder.plugin.zsh
75 lines (69 loc) · 2.13 KB
/
fzf-finder.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
(( $+commands[fzf] )) || return
(( $+functions[fzf-find-widget] )) && return
(( $+commands[fzf-tmux] )) || return
(( $+commands[bat] )) && FZF_FINDER_CAT='bat --color always {}' || FZF_FINDER_CAT='cat {}'
if [[ -z $FZF_FINDER_PAGER ]]; then
(( $+commands[bat] )) && FZF_FINDER_PAGER='bat' || FZF_FINDER_PAGER='less'
fi
fzf-finder-find() {
if (( $+commands[fd] )); then
if (( $+FZF_FINDER_FD_OPTS )); then
FINDER_OPTS=$FZF_FINDER_FD_OPTS
else
FINDER_OPTS='-t f'
fi
$commands[fd] $(echo $FINDER_OPTS )
else
if (( $+FZF_FINDER_FIND_OPTS )); then
FINDER_OPTS=$FZF_FINDER_FIND_OPTS
else
FINDER_OPTS="-type f -not -path './.git/*\'"
fi
find * $(echo $FINDER_OPTS)
fi
}
fzf-finder-widget-editor() {
local target
target="$(fzf-finder-find | \
fzf-tmux -1 -0 \
--no-sort \
--ansi \
--reverse \
--toggle-sort=ctrl-r \
--preview $FZF_FINDER_CAT \
)" \
&& if [[ -z $TMUX ]]; then \
${FZF_FINDER_EDITOR:-vim} "${target}"; \
else \
local this_session
local target_name
target_name=$(basename ${target}|sed -e 's/\./_/g')
this_session=$(tmux display-message -p '#S')
tmux new-window -t ${this_session} -n ${target_name} -d ${FZF_FINDER_EDITOR:-vim} "${target}"; \
tmux select-window -t ${target_name}
fi
local ret=$?
zle reset-prompt
typeset -f zle-line-init >/dev/null && zle zle-line-init
return $ret
}
fzf-finder-widget-pager() {
local target
target="$(fzf-finder-find | \
fzf-tmux -1 -0 \
--no-sort \
--ansi \
--reverse \
--toggle-sort=ctrl-r \
--preview $FZF_FINDER_CAT \
)"
${FZF_FINDER_PAGER} "${target}"
local ret=$?
zle reset-prompt
typeset -f zle-line-init >/dev/null && zle zle-line-init
return $ret
}
zle -N fzf-finder-widget-editor
bindkey ${FZF_FINDER_EDITOR_BINDKEY:-'\ee'} fzf-finder-widget-editor
zle -N fzf-finder-widget-pager
bindkey ${FZF_FINDER_PAGER_BINDKEY:-'\er'} fzf-finder-widget-pager