Make CTRL-T use tmux split when possible
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Junegunn Choi · committed by Junegunn Choi · parent 2b34665 · Browse files · 2 files·+51 added−20 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+51 added−20 removed
- other:+51 added−20 removed
Provenance
- Commit
ae86cdf- Tree
b0cc692- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
2b34665
2 files changed+51 added−20 removed
modified:install+46 added-19 removed
93 unmodified lines94 EOF95 96 if [ $key_bindings -eq 0 ]; then97 if [ $shell = bash ]; then98- cat >> $src << "EOF"98+ cat >> $src << "EOFZF"99 # Key bindings100 # ------------101 if [[ $- =~ i ]]; then102 103-__fsel() {103+read -r -d '' __fsel <<'EOF'104 find * -path '*/\.*' -prune \105 -o -type f -print \106 -o -type d -print \107 -o -type l -print 2> /dev/null | fzf -m | while read item; do108 printf '%q ' "$item"109 done110 echo111+EOF112+113+__fsel() {114+ eval "$__fsel"115 }116 117+__fsel_tmux() {118+ tmux split-window -l ${FZF_TMUX_HEIGHT:-15} "tmux send-keys -t $TMUX_PANE \"\$($__fsel)\""119+}120+121 __fcd() {122 local dir123 dir=$(find ${1:-*} -path '*/\.*' -prune -o -type d -print 2> /dev/null | fzf +m) && printf 'cd %q' "$dir"124 }125 126+__use_tmux=0127+[ -n "$TMUX_PANE" -a ${FZF_TMUX:-1} -ne 0 -a ${LINES:-30} -gt 15 ] && __use_tmux=1128+129 if [ -z "$(set -o | grep '^vi.*on')" ]; then130 # Required to refresh the prompt after fzf131 bind '"\er": redraw-current-line'132 133 # CTRL-T - Paste the selected file path into the command line134+ if [ $__use_tmux -eq 1 ]; then135+ 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"'136+ else123- 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"'137+ 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"'138+ fi139 140 # CTRL-R - Paste the selected command from history into the command line141 bind '"\C-r": " \C-e\C-u$(HISTTIMEFORMAT= history | fzf +s | sed \"s/ *[0-9]* *//\")\e\C-e\er"'142 4 unmodified lines147 bind '"\C-x\C-r": redraw-current-line'148 149 # CTRL-T - Paste the selected file path into the command line150 # - FIXME: Selected items are attached to the end regardless of cursor position136- bind '"\C-t": "\eddi$(__fsel)\C-x\C-e\e0P$a \C-x\C-r"'151+ if [ $__use_tmux -eq 1 ]; then152+ bind '"\C-t": "\e$a \eddi$(__fsel_tmux)\C-x\C-e\e0P$xa"'153+ else154+ bind '"\C-t": "\e$a \eddi$(__fsel)\C-x\C-e\e0Px$a \C-x\C-r"'155+ fi156 157 # CTRL-R - Paste the selected command from history into the command line158 bind '"\C-r": "\eddi$(HISTTIMEFORMAT= history | fzf +s | sed \"s/ *[0-9]* *//\")\C-x\C-e\e$a\C-x\C-r"'159 160 # ALT-C - cd into the selected directory161 bind '"\ec": "\eddi$(__fcd)\C-x\C-e\C-x\C-r\C-m"'162 fi163 164+unset __use_tmux165+166 fi146-EOF167+EOFZF168 else148- cat >> $src << "EOF"169+ cat >> $src << "EOFZF"170 # Key bindings171 # ------------172 # CTRL-T - Paste the selected file path(s) into the command line152-fzf-file-widget() {153- local FILES154- local IFS="155-"156- FILES=($(157- find * -path '*/\.*' -prune \173+read -r -d '' __fsel <<'EOF'174+ find * -path '*/\.*' -prune \175 -o -type f -print \176 -o -type d -print \160- -o -type l -print 2> /dev/null | fzf -m))161- unset IFS162- FILES=$FILES:q163- LBUFFER="${LBUFFER%% #} $FILES"164- zle redisplay165-}177+ -o -type l -print 2> /dev/null | fzf -m | while read item; do178+ printf '%q ' "$item"179+ done180+ echo181+EOF182+183+if [ -n "$TMUX_PANE" -a ${FZF_TMUX:-1} -ne 0 -a ${LINES:-30} -gt 15 ]; then184+ fzf-file-widget() {185+ tmux split-window -l ${FZF_TMUX_HEIGHT:-15} "tmux send-keys -t $TMUX_PANE \"\$($__fsel)\""186+ }187+else188+ fzf-file-widget() {189+ LBUFFER="${LBUFFER%% #}$(eval "$__fsel")"190+ zle redisplay191+ }192+fi193 zle -N fzf-file-widget194 bindkey '^T' fzf-file-widget195 196 # ALT-C - cd into the selected directory12 unmodified lines209 }210 zle -N fzf-history-widget211 bindkey '^R' fzf-history-widget212 186-EOF213+EOFZF214 fi215 fi216 217 echo "OK"26 unmodified linesmodified:README.md+5 added-1 removed
210 unmodified lines211 - `CTRL-T` - Paste the selected file path(s) into the command line212 - `CTRL-R` - Paste the selected command from history into the command line213 - `ALT-C` - cd into the selected directory214 215+If you're on a tmux session, `CTRL-T` will launch fzf in a new split-window. You216+may disable this tmux integration by setting `FZF_TMUX` to 0, or change the217+height of the window with `FZF_TMUX_HEIGHT`.218+219 The source code can be found in `~/.fzf.bash` and in `~/.fzf.zsh`.220 221 Auto-completion222 ---------------90 unmodified lines313 314 Note that the environment variables `FZF_DEFAULT_COMMAND` and `FZF_DEFAULT_OPTS`315 also apply here.316 313-If you're on a tmux session, `:FZF`, will launch fzf in a new split-window whose317+If you're on a tmux session, `:FZF` will launch fzf in a new split-window whose318 height can be adjusted with `g:fzf_tmux_height` (default: 15). However, the bang319 version (`:FZF!`) will always start in fullscreen.320 321 ### `fzf#run([options])`112 unmodified lines