[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] prompt help
From: |
Geir Hauge |
Subject: |
Re: [Help-bash] prompt help |
Date: |
Mon, 13 Feb 2012 21:13:27 +0100 |
2012/2/13 Chet Ramey <address@hidden>
> 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.
And here's using Chet's idea and with a different way of parsing PWD.
Putting the following block of code in ~/.bashrc should give you the
desired effect.
setmypwd() {
mypwd=$(
while read -rd /; do
printf /%.1s "$REPLY"
done <<< "${PWD#/}"
printf /%s "$REPLY"
)
}
cd() { builtin cd "$@" || return; setmypwd; }
pushd() { builtin pushd "$@" || return; setmypwd; }
popd() { builtin popd "$@" || return; setmypwd; }
setmypwd
PS1='address@hidden:$mypwd\$ '
> 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.
Not sure what scenarios you are thinking of there.
--
Geir Hauge