tmux fzf 快速搜索

警告
本文最后更新于 2023-09-13,文中内容可能已过时。

使用 tmux-fzf 快速搜索窗口。

修改 tmux-fzf

main.sh

vim ~/.tmux/plugins/tmux-fzf/main.sh:相当于关闭了其他的选项。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#!/usr/bin/env bash

CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
[[ -z "$TMUX_FZF_ORDER" ]] && TMUX_FZF_ORDER="session|window|pane|command|keybinding|clipboard|process"
source "$CURRENT_DIR/scripts/.envs"

## ==============================================
## only pane
item="pane"
#items_origin="$(echo $TMUX_FZF_ORDER | tr '|' '\n')"
#if [[ -z "$TMUX_FZF_MENU" ]]; then
#    item=$(printf "%s\n[cancel]" "$items_origin" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS")
#else
#    item=$(printf "menu\n%s\n[cancel]" "$items_origin" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS")
#fi
#[[ "$item" == "[cancel]" || -z "$item" ]] && exit
## ==============================================
item=$(echo "$CURRENT_DIR/scripts/$item" | sed -E 's/$/.sh/')
tmux run-shell -b "$item"

pane.sh

vim ~/.tmux/plugins/tmux-fzf/scripts/pane.sh:相当于只针对 switch 执行命令

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env bash

CURRENT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$CURRENT_DIR/.envs"

current_pane_origin=$(tmux display-message -p '#S:#{window_index}.#{pane_index}: #{window_name}')
current_pane=$(tmux display-message -p '#S:#{window_index}.#{pane_index}')

if [[ -z "$TMUX_FZF_PANE_FORMAT" ]]; then
    panes=$(tmux list-panes -a -F "#S:#{window_index}.#{pane_index}: [#{window_name}:#{pane_title}] #{pane_current_command}  [#{pane_width}x#{pane_height}] [history #{history_size}/#{history_limit}, #{history_bytes} bytes] #{?pane_active,[active],[inactive]}")
else
    panes=$(tmux list-panes -a -F "#S:#{window_index}.#{pane_index}: $TMUX_FZF_PANE_FORMAT")
fi

## ==============================================
## only switch
action="switch"
#FZF_DEFAULT_OPTS="$FZF_DEFAULT_OPTS --header='Select an action.'"
#if [[ -z "$1" ]]; then
#    action=$(printf "switch\nbreak\njoin\nswap\nlayout\nkill\nresize\nrename\n[cancel]" | eval "$TMUX_FZF_BIN $TMUX_FZF_OPTIONS")
#else
#    action="$1"
#fi
## ==============================================

##------------- 其他的复制原来的代码 --------------- ##
[[ "$action" == "[cancel]" || -z "$action" ]] && exit

tmux.conf 设置

使用 prefix-f

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
## fzf
set -g @plugin 'sainnhe/tmux-fzf'
## enable:1, disable:0
TMUX_FZF_PREVIEW=1
# prefix-f
TMUX_FZF_LAUNCH_KEY="f"
#TMUX_FZF_ORDER="session|window|pane|command|keybinding|clipboard|process"
TMUX_FZF_ORDER="pane|window|session"
##Default value in tmux >= 3.2
TMUX_FZF_OPTIONS="-p -w 90% -h 80% -m"
## menu
#TMUX_FZF_MENU=\
#"foo\necho 'Hello!'\n"\
#"bar\nls ~\n"\
#"sh\nsh ~/test.sh\n"

相关内容

william 支付宝支付宝
william 微信微信
0%