Programming

Automatically set window titles in GNU screen

Although GNU screen is actually a window manager, I mainly use it to turn nano into a tabbed text editor. If you do something similar, you might be interested in the way that I automatically set each window’s title to the filename that I’m editing (and reset it back to a default value when I exit the editor).

Make two additions to your .bashrc:

nano () { echo -ne "\ek${1##*/}\e\\"; /usr/bin/nano "$1"; }

This modifies the nano command to set the window title to the filename that’s being edited, sans any leading directories, before opening the file with the real nano. (If your true nano isn’t in /usr/bin/, make the appropriate substitution.)

export PROMPT_COMMAND='echo -ne "\ekbash\e\\"'

This has the effect of resetting the title to “bash” after nano exits, because the prompt has to be printed. (Note that it will reset any custom titles you set manually. There’s probably a better way to reset the title when a program exits, but this has worked for me.)

These two changes allow me to effectively use screen as a tabbed terminal text editor and see at a glance which files I have open in which “tabs.”

Standard