1
votes

I am trying to create a binding so that tmux copies last executed command to its copy buffer.

I tried following key bindings but it does not work. What happens when I press F5 is as follows:

  1. tmux shows copy mode without moving up
  2. I have to press q to exit copy mode
  3. tmux then sends the key up, so shell shows last execute command
  4. tmux's copy buffer has just newline

    bind-key -n F5 send-keys Up \; send-keys C-a \; copy-mode \; send-keys -X begin-selection \; send-keys -X begin-selection \; send-keys -X end-of-line \; send-keys -X copy-selection

I am using tmux 2.5 and connected to a server from which I connect to different servers in different tmux windows.

Essentially I want to execute the command on all windows by copying the last command in copy buffer and then pasting it different windows for replicating.

1
A was trying to use vim, history, xclip, but without satisfying results. Finally I give up with this combination: press "arrow up", press "home", type: "echo '", press "end", type "' | xclip", press "enter". I have alias xclip="xclip -selection c". I hope There will occur better answer.Daniel

1 Answers

0
votes

It is not answer about "copy last shell command", but it answers for your essential aim.

If you want to execute the command on all windows, then there is simplest solution:

Press:

Ctrl + a or Ctrl + b

And type:

:setw synchronize-panes

If you want to stop synchronization use command:

:setw synchronize-panes off

Sources

https://gist.github.com/andreyvit/2921703

https://sanctum.geek.nz/arabesque/sync-tmux-panes/