【问题标题】:tmux script for fast window switching with fzf-tmux gives me the wrong options使用 fzf-tmux 快速切换窗口的 tmux 脚本给了我错误的选项
【发布时间】:2016-06-09 16:00:38
【问题描述】:

我已经写了以下内容,它允许我用 fzf 切换 tmux 窗口:

tmux list-windows -F "#I:#W" | fzf-tmux | cut -d ":" -f 1 | xargs tmux select-window -t

当我在 shell 中运行它时,它运行良好,给了我一个 fzf 的窗口列表,我可以搜索并切换到。

我将它绑定到 tmux 中的 f 键:

# fast window switching
unbind f
bind-key f run "tmux list-windows -F \"#I:#W\" | fzf-tmux | cut -d \":\" -f 1 | xargs tmux select-window -t"

但是当我运行它时,它会显示同一个窗口 N 次(其中 N 是我打开的窗口数)。

所以如果我打开了 3 个窗口,在 zsh 中运行脚本会给我:

1. first window
2. second window
3. third window

tmux 键绑定给我的地方

1. first window
1. first window
1. first window

我以前没有写过 tmux 脚本,所以也许有比我在这里做的更好的获取 windows 的方法?否则,我不明白为什么从 tmux 运行并在 shell 中运行时会得到不同的选项。

更新:

似乎run-shell "tmux list-windows" 正确输出了不同的窗口(但有大量我不想要的布局信息),而run-shell "tmux list-windows -F '#I:#W'" 给了我原来的问题,即每个窗口条目都重复同一个窗口。

我认为问题在于 tmux 正在为 当前窗口 扩展 #I:#W,而不是将其传递给 list-windows 命令,所以我需要转义它们。关于如何做到这一点的任何想法?

更新 2:

答案是对变量进行双重哈希处理(##I:##W 而不是 #I:#W)。

【问题讨论】:

标签: tmux fzf


【解决方案1】:

感谢您分享您的解决方案!帮了我很多:)

对于看到这篇文章并想知道如何使用此命令在 tmux 会话之间切换的人:

bind-key C-f run-shell "tmux list-sessions -F \"##S\" | fzf-tmux | xargs tmux switch -t"

【讨论】:

    【解决方案2】:

    如果将来有人想使用这个脚本,正确的版本是这样的:

    # fast window switching
    bind -n C-f run-shell "tmux list-windows -F \"##I:##W\" | fzf-tmux | cut -d \":\" -f 1 | xargs tmux select-window -t"
    

    【讨论】:

    • 这对您有什么作用?当我运行命令时,我得到了'tmux list-windows -F "#I:#W" | fzf-tmux | cut -d ":" -f 1 | xargs tmux select-window -t' returned 123。
    • 是 tput 失败的问题:github.com/junegunn/fzf/issues/1032
    • 从 tmux 3.0a 开始,需要 -b 标志。见:github.com/junegunn/fzf/issues/1841#issuecomment-580975759。所以现在就是这样:bind -n C-f run-shell -b "tmux list-windows -F \"##I:##W\" | fzf-tmux | cut -d \":\" -f 1 | xargs tmux select-window -t"
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多