将 shell 命令的输出直接插入到 tmux 窗格中
Insert the output of a shell-command directly into a tmux pane
我的目标是复制 linux 中的鼠标中键复制粘贴功能。
我可以通过以下方式在窗格中显示此剪贴板的输出:
bind-key -T root MouseDown2Pane run-shell "xclip -selection primary -o"
我想直接将此输出插入到窗格中(即类似于 send-keys
),但我没有找到 link 将这两个命令放在一起的方法。
我是 运行 tmux 2.1 版。
这可以通过将 shell 命令的输出重定向到一个(临时文件),然后使用 tmux load-buffer
和 paste-buffer
命令:
bind-key -T root MouseDown2Pane run-shell "xclip -selection primary -o >~/.tmux-buffer-tmp" \; load-buffer -b tmp-copy-buffer ~/.tmux-buffer-tmp \; paste-buffer -b tmp-copy-buffer -d \; run-shell -b "rm ~/.tmux-buffer-tmp"
解释每一步:
run-shell "xclip -selection primary -o >~/.tmux-buffer-tmp"
使用 xclip 实用程序将剪贴板的内容插入临时文件
load-buffer -b tmp-copy-buffer ~/.tmux-buffer-tmp
将上述文件的内容加载到 tmux 缓冲区
paste-buffer -b tmp-copy-buffer -d
将这些内容直接粘贴到活动窗格中(并删除临时缓冲区,以便通过鼠标单击更改缓冲区的状态)
run-shell -b "rm ~/.tmux-buffer-tmp"
删除临时文件。
另一种不需要临时文件的方法是:
bind-key -T root MouseDown2Pane run-shell 'tmux set-buffer -b x-clip "$(xsel -op)"' \; paste-buffer -b x-clip -d
细分:
bind-key -T root MouseDown2Pane
:绑定到鼠标中键单击根键中的窗格table(当您未处于复制模式且未按下前缀时适用)
run-shell 'tmux set-buffer -b x-clip "$(xsel -op)"'
:这有点 hacky,但它在 shell 中运行 set-buffer
tmux 命令和另一个 tmux 命令。这样我们就可以扩展 xsel
命令的输出以获取剪贴板内容
paste-buffer -b x-clip -d
: 粘贴缓冲区的内容,并删除它。
另一种方法:
bind-key -T root MouseDown2Pane run-shell 'xclip -o | tmux load-buffer -bxclip -' \; paste-buffer -bxclip -d
我的目标是复制 linux 中的鼠标中键复制粘贴功能。
我可以通过以下方式在窗格中显示此剪贴板的输出:
bind-key -T root MouseDown2Pane run-shell "xclip -selection primary -o"
我想直接将此输出插入到窗格中(即类似于 send-keys
),但我没有找到 link 将这两个命令放在一起的方法。
我是 运行 tmux 2.1 版。
这可以通过将 shell 命令的输出重定向到一个(临时文件),然后使用 tmux load-buffer
和 paste-buffer
命令:
bind-key -T root MouseDown2Pane run-shell "xclip -selection primary -o >~/.tmux-buffer-tmp" \; load-buffer -b tmp-copy-buffer ~/.tmux-buffer-tmp \; paste-buffer -b tmp-copy-buffer -d \; run-shell -b "rm ~/.tmux-buffer-tmp"
解释每一步:
run-shell "xclip -selection primary -o >~/.tmux-buffer-tmp"
使用 xclip 实用程序将剪贴板的内容插入临时文件load-buffer -b tmp-copy-buffer ~/.tmux-buffer-tmp
将上述文件的内容加载到 tmux 缓冲区paste-buffer -b tmp-copy-buffer -d
将这些内容直接粘贴到活动窗格中(并删除临时缓冲区,以便通过鼠标单击更改缓冲区的状态)run-shell -b "rm ~/.tmux-buffer-tmp"
删除临时文件。
另一种不需要临时文件的方法是:
bind-key -T root MouseDown2Pane run-shell 'tmux set-buffer -b x-clip "$(xsel -op)"' \; paste-buffer -b x-clip -d
细分:
bind-key -T root MouseDown2Pane
:绑定到鼠标中键单击根键中的窗格table(当您未处于复制模式且未按下前缀时适用)run-shell 'tmux set-buffer -b x-clip "$(xsel -op)"'
:这有点 hacky,但它在 shell 中运行set-buffer
tmux 命令和另一个 tmux 命令。这样我们就可以扩展xsel
命令的输出以获取剪贴板内容paste-buffer -b x-clip -d
: 粘贴缓冲区的内容,并删除它。
另一种方法:
bind-key -T root MouseDown2Pane run-shell 'xclip -o | tmux load-buffer -bxclip -' \; paste-buffer -bxclip -d