Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!usc!snorkelwacker!paperboy!meissner From: meissner@osf.org (Michael Meissner) Newsgroups: comp.unix.questions Subject: Re: Pathname in prompt, not FAQ, really. Message-ID: Date: 12 Jun 90 15:13:58 GMT References: Sender: news@OSF.ORG Organization: Open Software Foundation Lines: 61 In-reply-to: avalon@tardis.computer-science.edinburgh.ac.uk's message of 12 Jun 90 10:29:33 GMT In article avalon@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@osf.org phone: 617-621-8861 Open Software Foundation, 11 Cambridge Center, Cambridge, MA Catproof is an oxymoron, Childproof is nearly so