tilde in ksh directory prompt

tilde in ksh directory prompt

Post by David W. Tamk » Sun, 28 Jun 1992 13:43:10

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


1. ksh: current directory in prompt

I've spent too much time trying to my korn shell prompt (PS1) to show
the current directory...  Help would be appreciated.  Thanks.

Laurie Kramer                           Genome Data Base

http://gdbdoc.gdb.org/~laurie/          http://gdbwww.gdb.org/
        "Nobody gets me. I'm the wind, baby." - Tom Servo

2. Using LINUX with EZ135 Cartridge Drive

3. Changing prompt to reflect new current working directory in ksh

4. Q: keeping a number oh jails up to date

5. Current directory display with ksh prompt

6. Creative CD200 CDROM supported???

7. Current directory in the ksh prompt?

8. Toshiba 4100 CDT and OSE5

9. directory in ksh prompt

10. Bash: expand tilde in prompt?

11. Tilde substitution in ksh

12. Tilde in ksh scripts

13. What's 'side effects' of Ksh built-ins?