[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] prompt help
From: |
Chet Ramey |
Subject: |
Re: [Help-bash] prompt help |
Date: |
Mon, 13 Feb 2012 08:43:01 -0500 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:8.0) Gecko/20111105 Thunderbird/8.0 |
On 2/13/12 8:31 AM, Greg Wooledge wrote:
> On Mon, Feb 13, 2012 at 01:37:39PM +0300, Mihamina Rakotomandimby wrote:
>> Hi all,
>>
>> Running Bash 4.2.20, I would like to have a prompt composed by the first
>> letters of the base path, excluding the last one.
>>
>>
>> Example:
>> - /u/l/bin if I'm in /usr/local/bin
>> - /v/w/h/my-website if I'm in /var/www/html/my-website
>> - /h/mihamina if I'm in /home/mihamina
>
> There are a couple approaches that will work for this. Both of them
> involve setting variables in your dot-files (~/.bashrc or ~/.bash_profile
> or ~/.profile). There are two variables that govern what bash does
> with the prompt: PROMPT_COMMAND and PS1. They are very different, but
> they can be made to work together.
I favor writing the code that Greg described, but calling it from function
replacements for `cd' (and, optionally, `pushd' and `popd'). That way you
avoid the overhead of reevaluating PS1 before every prompt by changing it
only when the current directory changes. You have to do a little more work
to make sure that the appropriate shell functions are defined in the right
subshells, but that's not hard.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU address@hidden http://cnswww.cns.cwru.edu/~chet/