Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将shell命令的输出直接插入到tmux窗格中_Shell_Copy Paste_Tmux - Fatal编程技术网

将shell命令的输出直接插入到tmux窗格中

将shell命令的输出直接插入到tmux窗格中,shell,copy-paste,tmux,Shell,Copy Paste,Tmux,我的目标是在linux中复制鼠标中键复制粘贴功能 我可以通过以下方式在窗格中显示此剪贴板的输出: bind-key -T root MouseDown2Pane run-shell "xclip -selection primary -o" 我想直接将此输出插入窗格(即类似于发送键),但我看不到将这两个命令链接在一起的方法 我正在运行tmux版本2.1。这可以通过将shell命令的输出重定向到一个(临时文件)中,然后使用tmux加载缓冲区和粘贴缓冲区命令将该文件的内容直接插入窗格来实现: bi

我的目标是在linux中复制鼠标中键复制粘贴功能

我可以通过以下方式在窗格中显示此剪贴板的输出:

bind-key -T root MouseDown2Pane run-shell "xclip -selection primary -o"
我想直接将此输出插入窗格(即类似于
发送键
),但我看不到将这两个命令链接在一起的方法


我正在运行tmux版本2.1。

这可以通过将shell命令的输出重定向到一个(临时文件)中,然后使用tmux
加载缓冲区
粘贴缓冲区
命令将该文件的内容直接插入窗格来实现:

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"
解释每个步骤:

  • 运行shell“xclip-selection primary-o>~/.tmux buffer tmp”
    使用xclip实用程序将剪贴板的内容插入到临时文件中
  • load buffer-b tmp copy buffer~/.tmux buffer tmp
    将上述文件的内容加载到tmux缓冲区中
  • 粘贴缓冲区-b tmp copy buffer-d
    将这些内容直接粘贴到活动窗格中(并删除临时缓冲区,以便通过单击鼠标使缓冲区的状态保持不变)
  • 运行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
    :绑定到鼠标中键单击root key表中的窗格(当您未处于复制模式且未按下前缀时适用)
  • 运行shell'tmux set buffer-bx-clip“$(xsel-op)”
    :这有点老套,但它使用另一个tmux命令在shell中运行
    set buffer
    tmux命令。这样我们就可以扩展
    xsel
    命令的输出,以获取剪贴板内容
  • 粘贴缓冲区-b x-clip-d
    :粘贴缓冲区的内容,然后将其删除
另一种方法是:

bind-key -T root MouseDown2Pane run-shell 'xclip -o | tmux load-buffer -bxclip -' \; paste-buffer -bxclip -d

除了中央按钮粘贴主功能外,我还使用此方法绑定
CONTROL+v
粘贴剪贴板:
bind key-T root C-v run shell….