The :; shell prompt trick

March 2, 2006

For years, I've had a somewhat unusual shell prompt. It looks like this:

: <host> ;

(where <host> is the hostname of the current machine.)

Putting the hostname in your prompt is pretty ordinary, but what's the other stuff? These days, a more typical shell prompt is something like 'cks@newman:~$ ', to quote a Debian example. (And many people use more elaborate prompts, such as Jamie Zawinksi's.)

The trick here is that the : and ; turn my prompt into a valid shell command that does nothing. This makes cutting and pasting previous commands in things like xterm much easier, since I don't have to carefully get just the command while avoiding the prompt. (In xterm it's just a quick triple click, but then xterm is very good at this.)

(In practice I am sufficiently neurotically neat that I select just the command, because seeing a doubled prompt looks wrong. This might be different if my prompt was just ':; ', but I need the host name in it to keep things straight.)

This trick is not original to me; I believe I got it from observing Geoff Collyer, many years ago.

Sidebar: xterm's double-click selections

One reason I don't use this more is that xterm's double-click selection mode makes selecting most things pretty fast anyways. For those who aren't aware of it, when you start a selection by double-clicking instead of single-clicking, xterm grows the selection by words instead of characters. (Try it; it's more intuitive than I make it sound.)

Embarrassingly, I spent years using xterm before I found out about this. Now I use it all the time, and hardly ever have to select by characters.

Comments on this page:

From at 2006-03-07 16:12:27:

With respect to double-click selections, I find it useful that xterm allows you to redefine how words are selected when double-clicking. Defining the X resource:

xterm*charClass:        33:48,45-47:48,64:48,126:48

will cause xterm to treat forward slashes, exclamation points, dashes, periods, at-signs and tildes the same as characters and numbers. This facilitates cutting and pasting complete pathnames and e-mail addresses by double-clicking. (One downside to this, of course, is that one cannot select partial pathnames by double-clicking when this resource is in effect.)

--Dan Astoorian

By cks at 2006-03-07 17:22:39:

The 'cannot select partial pathnames' issue is why I don't do this (and recently had to override a similar Fedora Core 4 change to xterm's defaults). I wind up selecting what would be partial bits often enough that I would rather swipe to widen the selection than to have to go character by character to do a partial selection.

I think this is partly because of the difference in precision needed. Selecting by characters requires high precision, so it's relatively annoying even if I do it relatively infrequently. Broadening by words requires low precision and is therefor quite fast and non-annoying, even if I do it routinely.

From at 2009-08-11 08:01:16:

A nice prompt trick I only recently saw, if your shell has a history mechanism, is including the line number, together with !:

   !23 mybox%

Then, you can select !23 with a double click and paste to repeat the command. I feel this is superior, especially if your command lines are long.

(I actually used to have the line number in my prompt for some time, but it never occurred to me to add the ! there already.)


Written on 02 March 2006.
« Unicode is not simple
A robots.txt surprise »

Page tools: View Source, View Normal, Add Comment.
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Thu Mar 2 02:47:41 2006
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.