help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] prompt help


From: Greg Wooledge
Subject: Re: [Help-bash] prompt help
Date: Mon, 13 Feb 2012 15:44:52 -0500
User-agent: Mutt/1.4.2.3i

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\$ '



reply via email to

[Prev in Thread] Current Thread [Next in Thread]