3

Here's my problem :

I have a particular setup with screen that I like to launch on startup, to quickly have access to several programs I use often.

Here's an example :

screen -U -S test -t shell

Within this screen session :

screen -t irc (in which I'll launch irssi) screen -t process (in which I'll launch top) ...

Note that this result in having one unique sessions, and multiple shells in this session. I specify it, because so far, my tests have brought me to the point where my script creates a screen session, in a session, in a session ... and I can't really figure out why.

I'd like to know if it's possible to build up a script that I could launch to create the whole screen setup and start the programs automatically when executed.

Thanks for any advices. =)

kRYOoX
  • 147
  • 4
  • You mean like `./awesome_startup_script` and then it opens only 1 screen with all the applications you normally use? – Braiam Dec 03 '13 at 16:35
  • That would be the idea. Basically, it should create one screen session, multiple shells in that sessions, and each shell gets its own program started. – kRYOoX Dec 03 '13 at 16:38
  • I would recommend using `tmux` to automatically set up something like this, but that's mostly personal preference, since `screen` should mostly be capable to do the same things. – n.st Dec 03 '13 at 18:14

2 Answers2

1

You can use screen -S sessionname -X command to run tmux-commands1 in an existing session, e.g. -X screen top to create a new window and run top in it. Note that the newly created window will be closed when the command terminates. If you would like to have a shell afterwards, use something like -X screen sh -c 'ls; bash'.

There are also ways to run commands in existing screen windows, see these two questions:

1: You can find the complete list of tmux commands on its manpage.

n.st
  • 1,908
  • 1
  • 17
  • 30
1

Create a ~/.screenrc file containing:

defutf8 on
sessionname test
screen -t shell   0
screen -t irc     1 irssi
screen -t process 2 top

Then, when you log in to the box, execute

screen -DR

which detaches any currently running screen and attaches to it, or if no screen is running it creates a new one.

glenn jackman
  • 25,463
  • 6
  • 46
  • 69
  • This worked wonderfully (for me). I didn't think about using the config file, shame on me =/ Thank you for the tip ! – kRYOoX Dec 05 '13 at 00:36