将文件从 tmux 窗格(或 window)目录复制到另一个窗格(或 window)目录

Copy file from tmux pane (or window) dir to another pane (or window) dir

示例:

2 个窗格。

窗格 1 当前目录:/a/b/c/d

窗格 2 当前目录:/a/f/g

我想将窗格 1 的当前目录中的 file.csv 复制到窗格 2 的当前目录。

我的工作:

在窗格 1 中:

cp file.csv ../../../f/g

从窗格 1 中的目录找到正确的相对路径既缓慢又烦人,我觉得我可以 "drag and drop" 从一个窗格到另一个窗格的文件。

有没有办法做类似于拖放的事情?

"good" 解决方案示例:

cp file.csv $pane2dir

谢谢

我遇到了同样的问题,为此我使用了 tmux-yank 插件。它具有将窗格当前工作目录复制到系统剪贴板的功能。 (免责声明:我是插件的作者。)

为了提供问题的完整答案,以下是我使用此插件执行的步骤:

  • 导航到 tmux 窗格 2,将窗格工作目录拉到剪贴板
  • 导航到 tmux 窗格 1,开始键入命令,然后将路径粘贴到 ctrl-vCmd-v 上 Mac

我的 tmux.conf

中有以下内容
# get directory from other pane using xsel
bind J run-shell -b -t bottom "echo -n #{pane_current_path} | xsel -i"
bind K run-shell -b -t top "echo -n #{pane_current_path} | xsel -i"
bind H run-shell -b -t left "echo -n #{pane_current_path} | xsel -i"
bind L run-shell -b -t right "echo -n #{pane_current_path} | xsel -i"

通常,我要复制到的窗格位于当前窗格的左侧或右侧。如果它在右侧,我会 <prefix> shift-l 将右侧窗格的当前目录放入剪贴板。

为了满足您的解决方案要求,可以修改它以创建一个命令,例如:

cp file.csv $(tmux run-shell -b -t right "echo -n #{pane_current_path} |xsel -i" && (sleep 0.01; xsel -o))

为了方便起见,将这些东西放在 shell 脚本中是有意义的。

给出我的答案后,我试了一下,想出了以下内容

bind L if-shell -b -t right "tmux set-buffer -b panedir #{pane_current_path}" "paste-buffer -db panedir"

将 "right" 窗格的当前目录直接放在命令行上。