Question

I'm trying to make a function in tmux so that when desired, I can bring up the command prompt (Ctrl-B, :) and type this in and have tmux spawn a new window in my existing session with a number of panes running a few specific commands.

Is this possible?

Was it helpful?

Solution

How about something like this:

Create a file called ~/foo.conf

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

We'll use neww to create the new window, then we'll issue commands to that new window. Using C-m sends the Enter key so the command executes. You could also pass the command to neww directly.

Then in your ~/.tmux.conf, bind it to a key

bind z source-file ~/foo.conf

This is just one way to pull this off. This particular scenario names the window, but with a little ingenuity, I'm sure you can come up with a workaround for that. Every tmux command can be issued from the .conf files, and can also be issued by passing it to tmux itself.

Hope that helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top