[LUNI] Customize the PS1 prompt

Martin Maney maney at pobox.com
Thu Jun 5 19:29:45 CDT 2003


On Thu, Jun 05, 2003 at 05:29:52PM -0500, doug_dallmer wrote:
> I am trying to customize the PS1 prompt to include the full path that it is
> currently in (ie: a "pwd" command) & ( including `pwd` doesn't work).

$ PS1="\u@\h (`pwd`) \$ "
maney at furrr (/home/maney) $

Or how 'bout:

$ PS1="\u@\h(`tty|sed \"s/\/dev\///\"`)\w \$ "
maney at furrr(pts/1)~ $

> According to the RedHat Linux 8 Bible I have this should be the inclusion of
> the "\w"; however it only returns a "~" in the prompt.   When I use a "\W" I
> get the current workng directory as expected.   This happens in both the 2.2
> and the 2.4 kernels.
> 
> Any ideas about fixing it?

The '~' will become more intersting if you ever cd to some other
directory.  \W should give you only the basename of the CWD:

$ PS1="\u@\h(`tty|sed \"s/\/dev\///\"`)\W \$ "
maney at furrr(pts/1)maney $

... but your milage may vary, since this is all done by the shell (my
examples are with bash).  The idea with the '~' is that it uses
$HOME-relative mode when you're within your login directory tree; it
shifts to the full, explicit path when you venture out.

One last example that's only useful in an xterm:

$ PS1="\[\033]0;(`tty|sed \"s/\/dev\///\"`) \u@\h:\w\007\]$ "
$

-- 
There's one way to find out if a man is honest: ask him;
if he says yes, you know he's crooked.  -- Twain



More information about the luni mailing list