mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-11-22 21:05:09 +00:00
fed5e5d5af
zle automatically calls zle-line-init when it starts to read a new line. Many Zsh setups use this hook to set the terminal into application mode, since this will then allow defining keybinds based on the $terminfo variable (the escape codes in said variable are only valid in application mode). However, fzf resets the terminal into raw mode, rendering $terminfo values invalid once the widget has finished. Accordingly, keyboard bindings defined via $terminfo won’t work anymore. This fixes the issue by calling zle-line-init when widgets finish. Care is taken to not call this widget when it is undefined. Fixes #279
69 lines
1.9 KiB
Bash
69 lines
1.9 KiB
Bash
# Key bindings
|
|
# ------------
|
|
if [[ $- == *i* ]]; then
|
|
|
|
# CTRL-T - Paste the selected file path(s) into the command line
|
|
__fsel() {
|
|
local cmd="${FZF_CTRL_T_COMMAND:-"command find -L . \\( -path '*/\\.*' -o -fstype 'dev' -o -fstype 'proc' \\) -prune \
|
|
-o -type f -print \
|
|
-o -type d -print \
|
|
-o -type l -print 2> /dev/null | sed 1d | cut -b3-"}"
|
|
setopt localoptions pipefail
|
|
eval "$cmd | $(__fzfcmd) -m $FZF_CTRL_T_OPTS" | while read item; do
|
|
echo -n "${(q)item} "
|
|
done
|
|
local ret=$?
|
|
echo
|
|
return $ret
|
|
}
|
|
|
|
__fzfcmd() {
|
|
[ ${FZF_TMUX:-1} -eq 1 ] && echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf"
|
|
}
|
|
|
|
fzf-file-widget() {
|
|
LBUFFER="${LBUFFER}$(__fsel)"
|
|
local ret=$?
|
|
zle redisplay
|
|
typeset -f zle-line-init >/dev/null && zle zle-line-init
|
|
return $ret
|
|
}
|
|
zle -N fzf-file-widget
|
|
bindkey '^T' fzf-file-widget
|
|
|
|
# ALT-C - cd into the selected directory
|
|
fzf-cd-widget() {
|
|
local cmd="${FZF_ALT_C_COMMAND:-"command find -L . \\( -path '*/\\.*' -o -fstype 'dev' -o -fstype 'proc' \\) -prune \
|
|
-o -type d -print 2> /dev/null | sed 1d | cut -b3-"}"
|
|
setopt localoptions pipefail
|
|
cd "${$(eval "$cmd | $(__fzfcmd) +m $FZF_ALT_C_OPTS"):-.}"
|
|
local ret=$?
|
|
zle reset-prompt
|
|
typeset -f zle-line-init >/dev/null && zle zle-line-init
|
|
return $ret
|
|
}
|
|
zle -N fzf-cd-widget
|
|
bindkey '\ec' fzf-cd-widget
|
|
|
|
# CTRL-R - Paste the selected command from history into the command line
|
|
fzf-history-widget() {
|
|
local selected num
|
|
setopt localoptions noglobsubst pipefail
|
|
selected=( $(fc -l 1 | eval "$(__fzfcmd) +s --tac +m -n2..,.. --tiebreak=index --toggle-sort=ctrl-r $FZF_CTRL_R_OPTS -q ${(q)LBUFFER}") )
|
|
local ret=$?
|
|
if [ -n "$selected" ]; then
|
|
num=$selected[1]
|
|
if [ -n "$num" ]; then
|
|
zle vi-fetch-history -n $num
|
|
fi
|
|
fi
|
|
zle redisplay
|
|
typeset -f zle-line-init >/dev/null && zle zle-line-init
|
|
return $ret
|
|
}
|
|
zle -N fzf-history-widget
|
|
bindkey '^R' fzf-history-widget
|
|
|
|
fi
|
|
|