Skip to content

Full Paths and the Multiline Shell Prompt

The shell prompt in bash can be modified to provide useful information. There are environmental variables that can be set to control the prompt string (see the bash manpage for more information). One of the more useful things, in my opinion, to include in the prompt string is the current path (so you always knows where you are without having to run pwd). The paths for deeply nested subdirectories can get quite long, however, leaving precious little space for commands. (Bash will wrap these, of course, but, still, annoying.) Dr. Drang details a solution in zsh that allows right-justified strings that can be overwritten. zsh is cool and all, but if you are not prepared to abandon bash (the default shell on OS X), you might try a multiline prompt. I have the following in my .profile:

PS1="\n\
\$PWD\n\
$BOLD\h-\u$DIM $ "; export PS1
PS2="more=> "; export PS2

Which produces the following shell prompt:

Prompt

How apt a solution this is will depend, of course, on how precious vertical space in the terminal is to you. (Dr. Drang mentioned something about his left eye twitching uncontrollably.) So your mileage may vary.

{ 1 } Trackback

  1. Bash Prompt Redux at Excursus | June 11, 2008 at 8:11 pm | Permalink

    […] so you know a meeting is boring when you would rather redo your bash prompt. (And, yes, as a consequence, I have come to appreciate the point of running a […]

Post a Comment

You must be logged in to post a comment.
FireStats icon Powered by FireStats