screen用起来很方便, 和xterm等虚拟终端配合起来更是花样多多. 例如, 我们可以根据screen的状态去动态地调整xterm的title. 这个功能我之前就实现过(传送门), 但是那些sequences很难懂, 我自己今天再看过都糊涂了, 所以赶紧记下.

hardstatus off
hardstatus string "screen(@%H): %t"
termcapinfo xterm* 'hs:ts=\E]0;:fs=\007:ds=\E]0;\007'

上面是我screen中这部分的配置, 第一句是禁止在hardstatus line中打印警告, 第二句是设置hardstatus line的内容(详见screen手册中的STRING ESCAPES), 第三句最难懂了, 它的意思是把xterm的titlebar当作screen的hardstatus line.

详细说第三句, hs表示终端有个hardstatus line, ts提供进入hardstatus line的 escape sequence, fs是离开时用的, ds是用于清除的. 它们各自的escape sequence是在xterm中定义的, 意义如下:

3.1 xterm escape sequences Window and icon titles may be changed in a running xterm by using XTerm escape sequences. The following sequences are useful in this respect:

ESC]0;stringBEL -- Set icon name and window title to string
ESC]1;stringBEL -- Set icon name to string
ESC]2;stringBEL -- Set window title to string

where ESC is the escape character (\033), and BEL is the bell character (\007).

PS: 发现自己真是挺能折腾的…