Is there a way to send a sequence of commands to GNU Screen windows from my .screenrc? It seems like this should be easy to do:
.screenrc:
startup_message off
screen -t "RAILS SERVER"
<send command to last created window> <my alias to cd Rails project>
<send command to last created window> rails s
screen -t "RAILS CONSOLE"
<send command to last created window> <my alias to cd to Rails project>
rails c
I've gone over the Screen man-page several times, but can't find anything that will <send command to last created window>
.
Thanks, Max
Keith's answer gets the job done but it ties the window to that process so that as soon as the application is done executing, the window closes.
Here's what I wound up doing that worked perfectly:
screen -t "RAILS SERVER"
stuff "cd $my_rails_directory; rails server^M"
screen -t "RAILS CONSOLE"
stuff "cd $my_rails_directory; rails console^M"
The important part to note here is the ^M character. This isn't actually a ^ followed by an M. This is a raw newline character. In almost any CLI program (vi, emacs, shell), you can press CTRL-V and then press ENTER to generate this character.
How does this work? The stuff command types the given string directly into the console. The newline literal at the end actually sends the command off the way you normally would if you typed it yourself. Hope that helps! I've found this approach to be far more stable and reliable than others.
It's not a separate command; you just specify the command to run on the line that creates the window.
For example (untested):
screen -t "RAILS SERVER" sh -c "cd ... ; rails s"
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