Apply fzf-tmux to key bindings (#203)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Note that CTRL-T on bash is still using the old trick of send-keys.
authored by Junegunn Choi · committed by Junegunn Choi · parent 651a8f8 · Browse files · 3 files·+31 added−57 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+31 added−57 removed
- other:+31 added−57 removed
Provenance
- Commit
318edc8- Tree
4c8af28- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
651a8f8
3 files changed+31 added−57 removed
modified:shell/key-bindings.bash+17 added-13 removed
123345673 unmodified lines111213141515161718192021222323242526262728292930313233343536373839404142434441454643474849504751525350545556575859606158626360646566676865697071726973747576772 unmodified lines# Key bindings# ------------__fsel() {__fzf_select__() { 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- | fzf -m | while read item; do3 unmodified lines}
if [[ $- =~ i ]]; then
__fsel_tmux() {__fzf_select_tmux__() { local height height=${FZF_TMUX_HEIGHT:-40%} if [[ $height =~ %$ ]]; then height="-p ${height%\%}" else height="-l $height" fi tmux split-window $height "cd $(printf %q "$PWD");bash -c 'source ~/.fzf.bash; tmux send-keys -t $TMUX_PANE \"\$(__fsel)\"'" tmux split-window $height "cd $(printf %q "$PWD");bash -c 'source ~/.fzf.bash; tmux send-keys -t $TMUX_PANE \"\$(__fzf_select__)\"'"}
__fcd() {__fzf_cd__() { local dir dir=$(command find -L ${1:-.} \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \ -o -type d -print 2> /dev/null | sed 1d | cut -b3- | fzf +m) && printf 'cd %q' "$dir" -o -type d -print 2> /dev/null | sed 1d | cut -b3- | fzf-tmux -d${FZF_TMUX_HEIGHT:-40%} +m) && printf 'cd %q' "$dir"}
__fzf_history__() { HISTTIMEFORMAT= history | fzf-tmux -d${FZF_TMUX_HEIGHT:-40%} +s --tac +m -n2..,.. --tiebreak=index --toggle-sort=ctrl-r | sed "s/ *[0-9]* *//"}
__use_tmux=0[ -n "$TMUX_PANE" -a ${FZF_TMUX:-1} -ne 0 -a ${LINES:-40} -gt 15 ] && __use_tmux=1
if [ -z "$(set -o | \grep '^vi.*on')" ]; then # Required to refresh the prompt after fzf bind '"\er": redraw-current-line'
# CTRL-T - Paste the selected file path into the command line if [ $__use_tmux -eq 1 ]; then bind '"\C-t": " \C-u \C-a\C-k$(__fsel_tmux)\e\C-e\C-y\C-a\C-d\C-y\ey\C-h"' bind '"\C-t": " \C-u \C-a\C-k$(__fzf_select_tmux__)\e\C-e\C-y\C-a\C-d\C-y\ey\C-h"' else bind '"\C-t": " \C-u \C-a\C-k$(__fsel)\e\C-e\C-y\C-a\C-y\ey\C-h\C-e\er \C-h"' bind '"\C-t": " \C-u \C-a\C-k$(__fzf_select__)\e\C-e\C-y\C-a\C-y\ey\C-h\C-e\er \C-h"' fi
# CTRL-R - Paste the selected command from history into the command line bind '"\C-r": " \C-e\C-u$(HISTTIMEFORMAT= history | fzf +s --tac +m -n2..,.. --tiebreak=index --toggle-sort=ctrl-r | sed \"s/ *[0-9]* *//\")\e\C-e\er"' bind '"\C-r": " \C-e\C-u$(__fzf_history__)\e\C-e\er"'
# ALT-C - cd into the selected directory bind '"\ec": " \C-e\C-u$(__fcd)\e\C-e\er\C-m"' bind '"\ec": " \C-e\C-u$(__fzf_cd__)\e\C-e\er\C-m"'else bind '"\C-x\C-e": shell-expand-line' bind '"\C-x\C-r": redraw-current-line'
# CTRL-T - Paste the selected file path into the command line # - FIXME: Selected items are attached to the end regardless of cursor position if [ $__use_tmux -eq 1 ]; then bind '"\C-t": "\e$a \eddi$(__fsel_tmux)\C-x\C-e\e0P$xa"' bind '"\C-t": "\e$a \eddi$(__fzf_select_tmux__)\C-x\C-e\e0P$xa"' else bind '"\C-t": "\e$a \eddi$(__fsel)\C-x\C-e\e0Px$a \C-x\C-r\exa "' bind '"\C-t": "\e$a \eddi$(__fzf_select__)\C-x\C-e\e0Px$a \C-x\C-r\exa "' fi bind -m vi-command '"\C-t": "i\C-t"'
# CTRL-R - Paste the selected command from history into the command line bind '"\C-r": "\eddi$(HISTTIMEFORMAT= history | fzf +s --tac +m -n2..,.. --tiebreak=index --toggle-sort=ctrl-r | sed \"s/ *[0-9]* *//\")\C-x\C-e\e$a\C-x\C-r"' bind '"\C-r": "\eddi$(__fzf_history__)\C-x\C-e\e$a\C-x\C-r"' bind -m vi-command '"\C-r": "i\C-r"'
# ALT-C - cd into the selected directory bind '"\ec": "\eddi$(__fcd)\C-x\C-e\C-x\C-r\C-m"' bind '"\ec": "\eddi$(__fzf_cd__)\C-x\C-e\C-x\C-r\C-m"' bind -m vi-command '"\ec": "i\ec"'fi
unset __use_tmux2 unmodified linesmodified:shell/key-bindings.fish+7 added-24 removed
24 unmodified lines25 end26 end27 28 function __fzf_ctrl_t29- if [ -n "$TMUX_PANE" -a "$FZF_TMUX" != "0" ]30- # FIXME need to handle directory with double-quotes31- tmux split-window (__fzf_tmux_height) "cd \"$PWD\";fish -c 'fzf_key_bindings; __fzf_ctrl_t_tmux \\$TMUX_PANE'"32- else33- __fzf_list | fzf -m > $TMPDIR/fzf.result34- and commandline -i (cat $TMPDIR/fzf.result | __fzf_escape)35- commandline -f repaint29+ __fzf_list | fzf-tmux (__fzf_tmux_height) -m > $TMPDIR/fzf.result30+ and commandline -i (cat $TMPDIR/fzf.result | __fzf_escape)31+ commandline -f repaint36- rm -f $TMPDIR/fzf.result37- end38- end39-40- function __fzf_ctrl_t_tmux41- __fzf_list | fzf -m > $TMPDIR/fzf.result42- and tmux send-keys -t $argv[1] (cat $TMPDIR/fzf.result | __fzf_escape)32 rm -f $TMPDIR/fzf.result33 end34 35 function __fzf_ctrl_r47- history | fzf +s +m --tiebreak=index --toggle-sort=ctrl-r > $TMPDIR/fzf.result36+ history | fzf-tmux (__fzf_tmux_height) +s +m --tiebreak=index --toggle-sort=ctrl-r > $TMPDIR/fzf.result37 and commandline (cat $TMPDIR/fzf.result)38 commandline -f repaint39 rm -f $TMPDIR/fzf.result40 end41 42 function __fzf_alt_c43 # Fish hangs if the command before pipe redirects (2> /dev/null)55- __fzf_list_dir | fzf +m > $TMPDIR/fzf.result44+ __fzf_list_dir | fzf-tmux (__fzf_tmux_height) +m > $TMPDIR/fzf.result45 [ (cat $TMPDIR/fzf.result | wc -l) -gt 0 ]46 and cd (cat $TMPDIR/fzf.result)47 commandline -f repaint48 rm -f $TMPDIR/fzf.result49 end50 51 function __fzf_tmux_height52 if set -q FZF_TMUX_HEIGHT64- set height $FZF_TMUX_HEIGHT53+ echo "-d$FZF_TMUX_HEIGHT"54 else66- set height 40%55+ echo "-d40%"56 end68- if echo $height | \grep -q -E '%$'69- echo "-p "(echo $height | sed 's/%$//')70- else71- echo "-l $height"72- end73- set -e height57 end58 59 bind \ct '__fzf_ctrl_t'60 bind \cr '__fzf_ctrl_r'3 unmodified linesmodified:shell/key-bindings.zsh+7 added-20 removed
3 unmodified lines4567889101112131415161718192021222324252627282930311617181932202122232425392627282930313233344835363738397 unmodified lines3 unmodified lines__fsel() { 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- | fzf -m | while read item; do -o -type l -print 2> /dev/null | sed 1d | cut -b3- | fzf-tmux -d${FZF_TMUX_HEIGHT:-40%} -m | while read item; do printf '%q ' "$item" done echo}
if [[ $- =~ i ]]; then
if [ -n "$TMUX_PANE" -a ${FZF_TMUX:-1} -ne 0 -a ${LINES:-40} -gt 15 ]; then fzf-file-widget() { local height height=${FZF_TMUX_HEIGHT:-40%} if [[ $height =~ %$ ]]; then height="-p ${height%\%}" else height="-l $height" fi tmux split-window $height "cd $(printf %q "$PWD");zsh -c 'source ~/.fzf.zsh; tmux send-keys -t $TMUX_PANE \"\$(__fsel)\"'" }else fzf-file-widget() { LBUFFER="${LBUFFER}$(__fsel)" zle redisplay }fzf-file-widget() { LBUFFER="${LBUFFER}$(__fsel)" zle redisplay}fizle -N fzf-file-widgetbindkey '^T' fzf-file-widget
# ALT-C - cd into the selected directoryfzf-cd-widget() { cd "${$(command find -L . \( -path '*/\.*' -o -fstype 'dev' -o -fstype 'proc' \) -prune \ -o -type d -print 2> /dev/null | sed 1d | cut -b3- | fzf +m):-.}" -o -type d -print 2> /dev/null | sed 1d | cut -b3- | fzf-tmux -d${FZF_TMUX_HEIGHT:-40%} +m):-.}" zle reset-prompt}zle -N fzf-cd-widgetbindkey '\ec' fzf-cd-widget
# CTRL-R - Paste the selected command from history into the command linefzf-history-widget() { local selected if selected=$(fc -l 1 | fzf +s --tac +m -n2..,.. --tiebreak=index --toggle-sort=ctrl-r -q "$LBUFFER"); then if selected=$(fc -l 1 | fzf-tmux -d${FZF_TMUX_HEIGHT:-40%} +s --tac +m -n2..,.. --tiebreak=index --toggle-sort=ctrl-r -q "$LBUFFER"); then num=$(echo "$selected" | head -1 | awk '{print $1}' | sed 's/[^0-9]//g') LBUFFER=!$num zle expand-history fi7 unmodified lines