tmux: how to bind a key to launch shell command?
7,542
Solution 1
C-b c
already has a standard binding which it might be wise to leave unchanged. Choosing another character, eg C-b C you can setup a binding in your
~/.tmux.conf
file as follows:
bind C send-keys -t.- 'mvn install' Enter
The -t.-
means "the other pane". Enter
stands for the key of that name, i.e. the newline at the end of the command.
Solution 2
The right answer to this question is: use bind-key
, e.g.:
tmux bind-key "$KEY" run-shell "/path/to/script.sh"
where KEY=C
in your case.
Related videos on Youtube
Author by
cdupont
Updated on September 18, 2022Comments
-
cdupont over 1 year
I use
tmux
to develop, with two panes: one to edit the code, and one to compile it. I need to switch pane very often to launch the compile command (say "mvn install
").
How can I bind a key (say "Ctrl+B C") to launch that specific command in the other pane (or without any pane at all)? -
cdupont over 5 yearsThanks. It's not clear to me where the command will be run? In which pane will be the output?
-
elquimista over 5 yearsThis should be the accepted answer. meuh's answer works but it simulates real human interaction, thus results in printing the command into the terminal pane.
-
elquimista over 5 yearsThanks for the solution. However, I learned that it also prints the command to the terminal pane due.