Pathname in prompt, not FAQ, really.

Michael Meissner meissner at osf.org
Wed Jun 13 01:13:58 AEST 1990


In article <sent.Tue.Jun.12.09:57:20.Lon.1990.via.CS.TARDIS>
avalon at tardis.computer-science.edinburgh.ac.uk ("Scott A.C. McIntyre")
writes:

| Im interested in finding out how I can get a Sys V type machine to 
| include my cwd in my prompt...Currently, what it does is what was
| suggested by the FAQ sheet that someone sent out a while ago, however,
| I was wondering if there was a better way..
| 
| Namely, when I am in my home directory I want it to display a ~ 
| instead of the path of my whole directory...secondly, I would like a
| prompt which when I hit cd and return would send me $home and change
| my prompt back to ~
| 
| Once upon a time in tcsh in BSD 4.3 I was able to use dirs in the prompt
| command...whenever I do that here, it ALWAYS returns a ~, which doesn't
| really help much...
| 
| And trying to just cd to get home gives me a no such file error...
| 
| Suggestions?  

Yes, if you are willing to switch shells.  The GNU Bourne Again Shell
has this feature.  For example, if you do:

	PS1='[\h]% '
	export PS1

it will display:

	[~]% 

if you are in your home directory,

	[~/subdir]%

if you in the subdirectory 'subdir' in your home directory, and
finally:

	[/tmp]%

if you are in the dictory /tmp.

In addition, both bash & ksh allows you to run arbitrary commands in
your prompt, via the $(command) syntax.  For example, I use something
similar to the following to give me the amount of free space in the
disk of the current directory.  The program free-space is a simple
hack I wrote to get the free space, and canonicalize the directory.
The '\' before the ${PWD} is needed for ksh, but not for bash.  For
bash, if you have a multiline prompt, like I use, you will need to
make a small fix to get the command line editing stuff to not mess
things up.

PS1='$(free-space -c \${PWD})
--> '
export PS1
--
Michael Meissner	email: meissner at osf.org		phone: 617-621-8861
Open Software Foundation, 11 Cambridge Center, Cambridge, MA

Catproof is an oxymoron, Childproof is nearly so



More information about the Comp.unix.questions mailing list