Tmux macro / function

I'm trying to make a function in tmux so that if I want to, I can invoke the command line (Ctrl-B, :) and type that value, and tmux create a new window in my existing session numbered from panes that execute a few specific commands.

Is it possible?


source to share

1 answer

How about something like this:

Create a file named ~/foo.conf

neww -n foo
send-keys -t foo cd ~/ C-m
send-keys -t foo vim C-m
split-window -t foo


We will use neww

to create a new window, then we will output commands to this new window. Usage C-m

sends the Enter key to execute the command. You could also send the command neww


Then ~/.tmux.conf

bind it to a key

bind z source-file ~/foo.conf


This is just one way to take it off. This particular script calls the window, but with a little ingenuity, I'm sure you can come up with a workaround for this. Each tmux command can be written out from .conf files and can also be issued by passing it on yourself tmux


Hope it helps!



All Articles