On Mon, Feb 13, 2012 at 09:13:27PM +0100, Geir Hauge wrote:
> 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"
> Â Â )
> }
This is forking a subshell, though. You can get around that by building
up the mypwd variable directly:
setmypwd() {
mypwd=""
while read -rd /; do
mypwd+="/${REPLY:0:1}"
done <<< "${PWD#/}"
mypwd+="/${REPLY%$'\n'}"
}
(Or use mypwd="${mypwd}stuff" for compatibility with pre-3.1 Bash.)
> cd() { builtin cd "$@" || return; setmypwd; }
> pushd() { builtin pushd "$@" || return; setmypwd; }
> popd() { builtin popd "$@" || return; setmypwd; }
>
> setmypwd
> PS1='address@hidden:$mypwd\$ '