Patching Bash so PS1='\W'
Prompt Shows ~ In $HOMEDIR

One of the trivial reasons I prefer tcsh to bash is this silly little problem with the prompt when using the \W option. (That option shows the basename of the current working directory). In tcsh it will show $HOMEDIR as a tilde, while bash prints out the literal "root" or "user" or whatever. Annoying.

But I do like to use both shells, and one day I got tired of this inconsistency and decided to fix it. Turned out to be very easy, so I'm posting a patch here against either bash-2.05 or bash-2.05b (if you want to be at the butter-knife edge; it's years old also).

If you just like typing for yourself, here's what the patch does:
   if (c == 'W')    /* in y.tab.c */
becomes:
   if (c == 'W' && (strcmp(get_string_value ("HOME"), temp) != 0))

On my Debian/Sarge system "make install" fails, but simply copying the bash binary into your path works just fine. If you're squeamish, just put it somewhere in your user $path and fool with it until you feel safe.

You can get the bash source here. If you're not familiar with this kind of thing, you'll want bash-2.05.tar.gz from near the middle of the page. Copy it someplace where you won't mess anything else up (say, ~/src), tar xvzf bash-2.05.tar.gz, change to the resultant bash-2.05 directory, copy the patch into it, type: patch < patch.diff and then type: make.

Eventually it will finish (if you have the compiler and other stuff necessary to build it) and if you wish you can type: make test. This will seem to stall at times, but might reassure you that it will work correctly.

After that you can try "make install" but it failed for me. No big deal; the other stuff it installs is the man pages (which you already have) and a bug reporter, which you shouldn't really use since you just altered the source.

Email:
D A V I D . M A R K . N O R T H


Copyright (C) 2004 David Mark North

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

You can also see it on the web here in all its glory (as of time of publication). If you like this patch, send them some money. They'll use it better than most folks would.