Attach to 'screen' session with creating a new screen window
I found something on the mailing list, thank you tuxuday :)
I'm doing it now this way:
#!/bin/bashscreen -X screen -t NEWWINDOW # create new window (switches existing attached terminal)sleep 0.1screen -X other # switch existing attached terminal back to its old windowsleep 0.1gnome-terminal -e 'screen -x -p NEWWINDOW' # connect to new window
I'm not sure about those sleeps, maybe they aren't necessary in all environments, but I can wait those 0.2s easily.
My .bash_aliases
is changing the screen window title with a delay, so the awkward NEWWINDOW
won't stick for long (and thus not hinder further calls to this script).
Add new detached window to sesion_name
and run command
screen -S sesion_name -x -X screen bash -c 'command; exec bash'
To choose a window to join, use the -p
option. Giving +
will create a new one, so your command is simply:
screen -x session_name -p +
This is documented on the man page:
-p n̲u̲m̲b̲e̲r̲_o̲r̲_n̲a̲m̲e̲|̲-̲|̲=̲|̲+̲
Preselect a window. This is useful when you want to reattach to a specific windor or you want to send a command via the "-X" option to a specific window. As with screen's select commant, "-" selects the blank window. As a special case for reattach, "=" brings up the windowlist on the blank window.