summaryrefslogtreecommitdiff
path: root/shell/key-bindings.bash
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2020-03-31 22:18:09 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2020-04-03 13:23:15 +0900
commitbf65e8cd12b0477a916ed16fa6d9d3ff9a78c824 (patch)
treeb2717ffe44d0d548a63359e5d18659bf6bb02a17 /shell/key-bindings.bash
parent0f5c6e8f040833ca632bb5ff345542879769225c (diff)
downloadfzf-bf65e8cd12b0477a916ed16fa6d9d3ff9a78c824.tar.gz
[fzf-tmux] Add option to start fzf in tmux popup window
Requires latest tmux built from source (e.g. brew install tmux --HEAD) Examples: # 50%/50% width and height on the center of the screen fzf-tmux -p # 80%/80% fzf-tmux -p80% # 80%/40% fzf-tmux -p80%,40% # Separate -w and -h fzf-tmux -w80% -h40% # 80%/40% at position (0, 0) fzf-tmux -w80% -h40% -x0 -y0 You can configure key bindings and fuzzy completion to open in tmux popup window like so: FZF_TMUX_OPTS='-p 80%'
Diffstat (limited to 'shell/key-bindings.bash')
-rw-r--r--shell/key-bindings.bash51
1 files changed, 20 insertions, 31 deletions
diff --git a/shell/key-bindings.bash b/shell/key-bindings.bash
index 16e1ec5b..a0b9eae0 100644
--- a/shell/key-bindings.bash
+++ b/shell/key-bindings.bash
@@ -1,3 +1,16 @@
+# ____ ____
+# / __/___ / __/
+# / /_/_ / / /_
+# / __/ / /_/ __/
+# /_/ /___/_/ key-bindings.bash
+#
+# - $FZF_TMUX_OPTS
+# - $FZF_CTRL_T_COMMAND
+# - $FZF_CTRL_T_OPTS
+# - $FZF_CTRL_R_OPTS
+# - $FZF_ALT_C_COMMAND
+# - $FZF_ALT_C_OPTS
+
# Key bindings
# ------------
__fzf_select__() {
@@ -5,7 +18,7 @@ __fzf_select__() {
-o -type f -print \
-o -type d -print \
-o -type l -print 2> /dev/null | cut -b3-"}"
- eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_CTRL_T_OPTS" fzf -m "$@" | while read -r item; do
+ eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse $FZF_DEFAULT_OPTS $FZF_CTRL_T_OPTS" $(__fzfcmd) -m "$@" | while read -r item; do
printf '%q ' "$item"
done
echo
@@ -13,35 +26,15 @@ __fzf_select__() {
if [[ $- =~ i ]]; then
-__fzf_use_tmux__() {
- [ -n "$TMUX_PANE" ] && [ "${FZF_TMUX:-0}" != 0 ] && [ ${LINES:-40} -gt 15 ]
-}
-
__fzfcmd() {
- __fzf_use_tmux__ &&
- echo "fzf-tmux -d${FZF_TMUX_HEIGHT:-40%}" || echo "fzf"
-}
-
-__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"); FZF_DEFAULT_OPTS=$(printf %q "$FZF_DEFAULT_OPTS") PATH=$(printf %q "$PATH") FZF_CTRL_T_COMMAND=$(printf %q "$FZF_CTRL_T_COMMAND") FZF_CTRL_T_OPTS=$(printf %q "$FZF_CTRL_T_OPTS") bash -c 'source \"${BASH_SOURCE[0]}\"; RESULT=\"\$(__fzf_select__ --no-height)\"; tmux setb -b fzf \"\$RESULT\" \\; pasteb -b fzf -t $TMUX_PANE \\; deleteb -b fzf || tmux send-keys -t $TMUX_PANE \"\$RESULT\"'"
+ [ -n "$TMUX_PANE" ] && { [ "${FZF_TMUX:-0}" != 0 ] && [ ${LINES:-40} -gt 15 ] || [ -n "$FZF_TMUX_OPTS" ]; } &&
+ echo "fzf-tmux ${FZF_TMUX_OPTS:--d${FZF_TMUX_HEIGHT:-40%}} -- " || echo "fzf"
}
fzf-file-widget() {
- if __fzf_use_tmux__; then
- __fzf_select_tmux__
- else
- local selected="$(__fzf_select__)"
- READLINE_LINE="${READLINE_LINE:0:$READLINE_POINT}$selected${READLINE_LINE:$READLINE_POINT}"
- READLINE_POINT=$(( READLINE_POINT + ${#selected} ))
- fi
+ local selected="$(__fzf_select__)"
+ READLINE_LINE="${READLINE_LINE:0:$READLINE_POINT}$selected${READLINE_LINE:$READLINE_POINT}"
+ READLINE_POINT=$(( READLINE_POINT + ${#selected} ))
}
__fzf_cd__() {
@@ -75,11 +68,7 @@ bind -m emacs-standard '"\C-z": vi-editing-mode'
if [ "${BASH_VERSINFO[0]}" -lt 4 ]; then
# CTRL-T - Paste the selected file path into the command line
- if __fzf_use_tmux__; then
- bind -m emacs-standard '"\C-t": " \C-b\C-k \C-u`__fzf_select_tmux__`\e\C-e\C-a\C-y\C-h\C-e\e \C-y\ey\C-x\C-x\C-f"'
- else
- bind -m emacs-standard '"\C-t": " \C-b\C-k \C-u`__fzf_select__`\e\C-e\er\C-a\C-y\C-h\C-e\e \C-y\ey\C-x\C-x\C-f"'
- fi
+ bind -m emacs-standard '"\C-t": " \C-b\C-k \C-u`__fzf_select__`\e\C-e\er\C-a\C-y\C-h\C-e\e \C-y\ey\C-x\C-x\C-f"'
bind -m vi-command '"\C-t": "\C-z\C-t\C-z"'
bind -m vi-insert '"\C-t": "\C-z\C-t\C-z"'