Search this site


Metadata

Articles

Projects

Presentations

Terminals, titles, and prompts.

Drew Stephens spent some time on Christmas to share some of his shell configuration, including different ways he uses prompts and colors.

I'll start with prompts.

I use zsh. My prompt looks like this:

# Plain
snack(~) % 

# Long directory is truncated at the left
snack(...jects/grok/ruby/test/general) % 

# I get exit status only if it is nonzero:
snack(~) % true
snack(~) % false
snack(~) !1! % 

# if I am root, and using zsh, the '%' becomes '#'
snack(~) # 
This is all achieved with the following PS1 in zsh:
PS1='%m(%35<...<%~) %(?..!%?! )%# '
We have configurable prompts to give us all kinds of information, why? It's a place to gather context from. I include host, directory, exit status, and an "am i root" flag.

PS1 isn't the only place you can store useful state. I like to have similar information in my terminal's titlebar, too. I use screen and xterm, and both can be fed some delicious data.

I use this in my .screenrc, which tells screen to have some default status format and tells screen how to change xterm's title. I have it include the screen window number (%n), hostname (%h), and terminal title (%t):

hardstatus string "[%n] %h - %t"
termcapinfo xterm 'hs:ts=\E]2;:fs=\007:ds=\E]2;screen (not title yet)\007'
windowlist title "Num Name%=Location Flags"
windowlist string "%03n %t%=%h %f"
I also use this bit of .vimrc, which tells vim what kind of title I want, and if the $TERM is screen, how to tell screen about it.
" Set title string and push it to xterm/screen window title
set titlestring=vim\ %<%F%(\ %)%m%h%w%=%l/%L-%P
set titlelen=70
if &term == "screen"
  set t_ts=^[k
  set t_fs=^[\
endif
if &term == "screen" || &term == "xterm" 
  set title
endif
And then use this bit of my zshrc.

All of these combined together make for some pretty good terminal and screen titles. The functions preexec, precmd, and title, mentioned below, come from the above zshrc link.

The preexec function in my zshrc runs before each command execution and allows me to change the terminal title to reflect the command I am running. It also supports resumed execution of a process: if you run 'cat', then hit ^Z, then type 'fg', the title will correctly be set to 'cat' again.

The precmd function runs before each prompt. Rather than cluttering up $PS1 with byte strings to set the title, I just make precmd set the title to 'zsh - $PWD'.

The title function takes care of any necessary escaping and also does nice things like string truncation if it is too long (similar to how my $PS1 is configured).

I only use vim's titlestring options because it gives me some better context on what I am doing in vim at the time, mainly because vim allows you to edit multiple files at once.

Here's an example of a few screen windows in a single screen session when viewed in the windowlist:

The first 3 columns are most meaningful: number, name, and location. Note that each location correctly identifies the host that shell is using. My zshrc 'title' function manages setting the name and the location.

The same data listed above is combined into the actual terminal's title. Window 2 above would have this title in xterm:

[2] jls - zsh - /home/jsissel

I mentioned above that I use screen and xterm together. I do this for everything using run-xterm.sh. This script will run screen in an xterm with a randomly chosen, dark color background. I find the dark-random color selection quite a nice deviation from the solid-black my desktop used to bear. Here's what it looks like if I run a 20+ xterms on a blank desktop:


4 responses to 'Terminals, titles, and prompts.'

Showing last 4 comments... (Click here to view all comments)

nixar wrote at Tue Dec 29 07:28:02 2009...
You're use xterm? In 2009? What is wrong with you?

Do you hate Unicode support?
Or is it anti-aliasing you can't stand?
Or speed?
Transparency support has cooties?
What about usability? You hate that too?

The stock gnome-terminal is light years beyond xterm and does all that. Same for KDE's terminal apps.

Jordan Sissel wrote at Wed Dec 30 10:29:09 2009...
I don't hate Unicode support, I just don't need it today.

Font anti-aliasing has nothing to do with it. Though I notice the font selection dialog is missing the font I use and like in xterm (suxus). That's not a win for gnome-terminal.

I don't know what you mean regarding "speed" as I've never thought xterm was slow. If I make a file with 1MB of random data, then 'time cat -v' that file for the sake of having some big data to output, it takes 3 seconds on xterm and 9 seconds on gnome-terminal. For comparison, konsole takes 1.6 seconds. What "speed" are you talking about? Surely nothing I've noticed.

I don't use transparency, and I find xterm quite usable. I don't need tabs in my terminal as ion (window manager) gives me those.

But overall, it's just a terminal to me. I'm not sure what features you think I need, but your idea of what I need is probably incorrect, and as detailed above, gnome-terminal doesn't fit me.

nixar wrote at Thu Dec 31 03:41:19 2009...
Regarding speed, gnome-terminal was faster than xterm in important use cases because it decided to not print everything when the incoming data couldn't be displayed fast enough (everything is in the buffer though). XTerm dutifully displayed everything. I guess on fast hardware this does not happen so the point is moot, and the time result you get is more a result of the cutoff threshold for display refresh.

As for anti-aliasing, I'm shocked. I can't go back to bitmap fonts (which must be what you're using if you don't see it in the Gnome font selector).

Transparency is more useful than you'd think. I set the background at 80% transparency and have Compiz blur behind terminal windows, and that allows me to detect if something moves on a window behind, without it being intrusive.

Jordan Sissel wrote at Wed Jan 6 16:04:56 2010...
I see the value in transparent/translucent windows, but I don't need them. With my current window manager, ion, there's nothing behind anything. All windows are in frames that do not overlap.

Transparency is nice for popups or overlays like with Growler (OS X). And if I didn't have a framed window manager, I'm sure I'd find other uses for it :)


Leave a reply

You need javascript enabled to use this form. Anti-spam efforts ongoing. Also, if the comment doesn't show up, it's because the form expired. Go back and copy your comment, reload the form, and resubmit. Apologies if this is a hassle, I'm just playing with antispam methods right now. If this insists on not working, please email me about it.

Name (required)
E-mail (optional, if you want me to be able to email you back)
URL (also optional)
Comment: