* [[Xpra|Xpra - An utility to detach/reattach X programs, in a way similar as screen does for command line based programs]]

Revision as of 15:46, 9 January 2013

zh-CN:GNU ScreenGNU Screen is a wrapper that allows separation between the text program and the shell from which it was launched. This allows the user to, for example, start a text program in a terminal in X, kill X, and continue to interact with the program. Here are a couple of tips and tricks you may be interested in.

Detach from the current screen session, and leave it running. Use screen -r to resume

Start at window 1

By default, the first screen window is 0. If you'd rather never have a window 0 and start instead with 1, put something like the following in your ~/.screenrc:

bind c screen 1
bind ^c screen 1
bind 0 select 10
screen 1

Nested Screen Sessions

It is possible to get stuck in a nested screen session. A common scenario: you start an ssh session from within a screen session. Within the ssh session, you start screen. By default, the outer screen session that was launched first responds to C-a commands. To send a command to the inner screen session, use C-a a, followed by your command. For example:

C-a a d

Detaches the inner screen session.

C-a a K

Kills the inner screen session.

Fix for residual editor text

When you open a text editor like nano in screen and then close it, the text may stay visible in your terminal. To fix this, put the following in your ~/.screenrc:

altscreen on

Use 256 colors

By default, screen uses an 8-color terminal emulator. Use the following line to enable more colors, which is useful if you are using a more-capable terminal emulator:

term screen-256color

If this fails to render 256 colors in xterm, try the following instead:

The above line uses mingetty to automatically login some user to a virtual console on startup. You will need to install the mingetty package from the official repositories. The inittab line segments are separated by colons. The first part (scr*) is simply an id. The second part is the runlevel: This should only happen on runlevel 4 (which is not used in any default setup - 3 is by default for a tty login and 5 is for X). 'Respawn' causes init to repeat the command (i.e. autologin) if the user logs out.
We will need to see that nothing else happens on virtual console 1 when we use runlevel 4, so remove 4 from the the first of the agetty lines:

c1:235:respawn:/sbin/agetty -8 38400 vc/1 linux

Once we are logged in, we want to ensure that screen is started. Add the following to the end of your ~/.bash_profile:

Set inittab/mingetty to automatically log in to vc/3 on runlevel 5 and you are set.

Fix Midnight Commander hard hang when starting in screen

In some cases (need deeper inspection) old gpm bug gets alive. So, then you try to run mc inside screen, you get a frozen screen window. Try to kill gpm daemon before starting mc and/or disable it in /etc/rc.conf.