I'm trying to write a script that will setup tmux windows for rails development, so far I have this:
#!/bin/bash
tmux new-window -n vim
tmux new-window -n guard
tmux new-window -n console/server
tmux select-window -t 3
tmux send-keys -t 3 'rails server' C-z
What I want, on that specific window, is to run rails server
and then send it to the background. The thing is, all I get is ^Z
and the usual prompt after a couple of seconds.
How can I accomplish this?
You can also access a tmux command line and type tmux commands by name. For example, to create a new window the hard way, you can press Ctrl+B followed by : to enter the tmux command line. Type new-window and press Enter to create a new window. This does exactly the same thing as pressing Ctrl+B then C.
Configure Terminal to start tmux by defaultbash_profile shell startup file, just above your aliases section. Save the file and close it. Then close and reopen the terminal to start using tmux by default, every time you open a terminal window.
Using the Prefixes to Control Tmux By default, the prefix is CTRL+B. That is, we have to press the keys CTRL+B and then the command. For example, to create a new session, the command would be C. So, to create a new session we need to press CTRL+B and next C – CTRL+B, C.
You can combine those tmux commands so that they’re all received by the same session. Separate by \;
(escaped to get all the way to tmux):
#!/bin/bash
tmux new -stest \; \
new-window -n vim \; \
new-window -n guard \; \
new-window -n console/server
select-window -t 3 \; \
send-keys -t 3 'rails s &' Enter
I don't see the C-z
working, but you can achieve the same with &
backgrounding.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With