First, I understand that this is already built into some shells, but I don't
own any of the sites where I log in, so "twist your sysadmins' arms to get
and install my favorite shell" is not a practicable answer.
Second, if you saw the first version of this article before I canceled it,
please ignore it.
Currently my PS1 is set to `hostname`:'${PWD#HOME/}> ' [actually I have the
hostname written out rather than having .profile look it up] and ksh very
politely replaces the current directory at every prompt. If it is my $HOME
or a directory not under my $HOME, it shows the whole path to the current
directory from /; if it is one under my $HOME [but not $HOME itself], PS1
shows the directory chain under my $HOME; the absence of the initial
foreslash indicates that it's figured from $HOME rather than root.
So far so good, but is there a way to get these:
1. If the current directory is not my $HOME nor anything under it, I'd like
what I have now: `hostname`:'$PWD> ';
2. If it is $HOME or anything under it, I'd like a tilde replacing the path
component matching $HOME: `hostname`:'~${PWD#$HOME}> '.
Thus in a directory under $HOME there would be ~/ instead of nothing and in
my $HOME I'd see ~ instead of the full length of $HOME.
I can get around it with an alias-function combination, but it's really ugly.
What I'd really like to do is just to handle it within the definition of PS1,
but I've tried putting case statements and the like there with various sorts
of quoting and evalling but I just can't get the right pieces evaluated at
the right times. In particular $PWD tends either to get evaluated when PS1
is defined or to remain literally dollar-capital P-capital S-1 no matter what.
David W. Tamkin Box 59297 Northtown Station, Illinois 60659-0297