Execute commands in GNU screen windows from .screenrc

Is there a way to send a sequence of commands to the GNU screen windows from my .screenrc? 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 looked through the Screen man page several times, but I can’t find anything that will be <send command to last created window> .

Thanks Max

+6
source share
2 answers

This is not a separate team; you simply specify the command to run in the line that creates the window.

For example (untested):

 screen -t "RAILS SERVER" sh -c "cd ... ; rails s" 
+5
source

Keith's answer does the job, but binds the window to this process, so that as soon as the application is completed, the window closes.

Here is what I did while working 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 here is the ^ M character. This is actually not ^ followed by 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 create this character.

How it works? The stuff command enters this line directly into the console. The newline literal at the end actually sends the command as usual if you typed it yourself. Hope this helps! I found this approach much more stable and reliable than others.

+13
source

Source: https://habr.com/ru/post/898212/


All Articles