summaryrefslogtreecommitdiffstats
path: root/shell
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
parent0f5c6e8f040833ca632bb5ff345542879769225c (diff)
[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')
-rw-r--r--shell/completion.bash8
-rw-r--r--shell/completion.zsh8
-rw-r--r--shell/key-bindings.bash51
-rw-r--r--shell/key-bindings.fish19
-rw-r--r--shell/key-bindings.zsh21
5 files changed, 60 insertions, 47 deletions
diff --git a/shell/completion.bash b/shell/completion.bash
index b1f7ac97..377afe56 100644
--- a/shell/completion.bash
+++ b/shell/completion.bash
@@ -2,10 +2,10 @@
# / __/___ / __/
# / /_/_ / / /_
# / __/ / /_/ __/
-# /_/ /___/_/-completion.bash
+# /_/ /___/_/ completion.bash
#
# - $FZF_TMUX (default: 0)
-# - $FZF_TMUX_HEIGHT (default: '40%')
+# - $FZF_TMUX_OPTS (default: empty)
# - $FZF_COMPLETION_TRIGGER (default: '**')
# - $FZF_COMPLETION_OPTS (default: empty)
@@ -37,9 +37,9 @@ bind '"\e[0n": redraw-current-line'
__fzf_comprun() {
if [ "$(type -t _fzf_comprun 2>&1)" = function ]; then
_fzf_comprun "$@"
- elif [ -n "$TMUX_PANE" ] && [ "${FZF_TMUX:-0}" != 0 ] && [ ${LINES:-40} -gt 15 ]; then
+ elif [ -n "$TMUX_PANE" ] && { [ "${FZF_TMUX:-0}" != 0 ] && [ ${LINES:-40} -gt 15 ] || [ -n "$FZF_TMUX_OPTS" ]; }; then
shift
- fzf-tmux -d "${FZF_TMUX_HEIGHT:-40%}" "$@"
+ fzf-tmux ${FZF_TMUX_OPTS:--d${FZF_TMUX_HEIGHT:-40%}} -- "$@"
else
shift
fzf "$@"
diff --git a/shell/completion.zsh b/shell/completion.zsh
index e828a704..e791b3a7 100644
--- a/shell/completion.zsh
+++ b/shell/completion.zsh
@@ -2,10 +2,10 @@
# / __/___ / __/
# / /_/_ / / /_
# / __/ / /_/ __/
-# /_/ /___/_/-completion.zsh
+# /_/ /___/_/ completion.zsh
#
# - $FZF_TMUX (default: 0)
-# - $FZF_TMUX_HEIGHT (default: '40%')
+# - $FZF_TMUX_OPTS (default: '-d 40%')
# - $FZF_COMPLETION_TRIGGER (default: '**')
# - $FZF_COMPLETION_OPTS (default: empty)
@@ -99,9 +99,9 @@ fi
__fzf_comprun() {
if [[ "$(type _fzf_comprun 2>&1)" =~ function ]]; then
_fzf_comprun "$@"
- elif [ -n "$TMUX_PANE" ] && [ "${FZF_TMUX:-0}" != 0 ] && [ ${LINES:-40} -gt 15 ]; then
+ elif [ -n "$TMUX_PANE" ] && { [ "${FZF_TMUX:-0}" != 0 ] && [ ${LINES:-40} -gt 15 ] || [ -n "$FZF_TMUX_OPTS" ]; }; then
shift
- fzf-tmux -d "${FZF_TMUX_HEIGHT:-40%}" "$@"
+ fzf-tmux ${(Q)${(Z+n+)FZF_TMUX_OPTS:--d${FZF_TMUX_HEIGHT:-40%}}} -- "$@"
else
shift
fzf "$@"
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"'
diff --git a/shell/key-bindings.fish b/shell/key-bindings.fish
index c4bad838..73a07334 100644
--- a/shell/key-bindings.fish
+++ b/shell/key-bindings.fish
@@ -1,3 +1,16 @@
+# ____ ____
+# / __/___ / __/
+# / /_/_ / / /_
+# / __/ / /_/ __/
+# /_/ /___/_/ key-bindings.fish
+#
+# - $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
# ------------
function fzf_key_bindings
@@ -84,8 +97,10 @@ function fzf_key_bindings
function __fzfcmd
test -n "$FZF_TMUX"; or set FZF_TMUX 0
test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
- if [ $FZF_TMUX -eq 1 ]
- echo "fzf-tmux -d$FZF_TMUX_HEIGHT"
+ if [ -n "$FZF_TMUX_OPTS" ]
+ echo "fzf-tmux $FZF_TMUX_OPTS -- "
+ else if [ $FZF_TMUX -eq 1 ]
+ echo "fzf-tmux -d$FZF_TMUX_HEIGHT -- "
else
echo "fzf"
end
diff --git a/shell/key-bindings.zsh b/shell/key-bindings.zsh
index fa8dbe7e..f8cb7821 100644
--- a/shell/key-bindings.zsh
+++ b/shell/key-bindings.zsh
@@ -1,3 +1,16 @@
+# ____ ____
+# / __/___ / __/
+# / /_/_ / / /_
+# / __/ / /_/ __/
+# /_/ /___/_/ key-bindings.zsh
+#
+# - $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
# ------------
@@ -40,13 +53,9 @@ __fsel() {
return $ret
}
-__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"
+ [ -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() {