Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 17 Nov 2009 18:29:41 -0500
From:      "Michael P. Soulier" <msoulier@digitaltorque.ca>
To:        Polytropon <freebsd@edvax.de>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: bash prompt update lagging
Message-ID:  <20091117232940.GB6951@anton.digitaltorque.ca>
In-Reply-To: <20091116031758.0729246c.freebsd@edvax.de>
References:  <20091115231424.GA29418@anton.digitaltorque.ca> <20091116031758.0729246c.freebsd@edvax.de>

next in thread | previous in thread | raw e-mail | index | archive | help

--b5gNqxB1S1yM7hjW
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On 16/11/09 Polytropon said:

> Your PS1 seems to include ${SHORT_PWD}, a variable. It seems
> that it is not updated immediately after the cd command.

Yeah, looks like it. Works on linux though...

> By the way, this is bash-3.2.25 on FreeBSD/x86 7.

bash-4.0.33_2 on x86 6.3.

> Is this what you've intended the prompt to look like?

I'm using an awk script to truncate any pwd that's too long.

get_short_pwd()
{
    # The actual max length is max_len + the length of trunc_symbol
    local max_length=3D$1
    local trunc_symbol=3D"..."

    if [ -z "$max_length" ]; then
            max_length=3D20
    fi

    if [ "$PWD" !=3D "$OLDPWD" ]; then
    SHORT_PWD=3D$(awk "BEGIN {               =20
            path =3D ENVIRON[\"PWD\"]
            home =3D ENVIRON[\"HOME\"]
            home_len =3D length(home)
            max_len =3D $max_length
            sym_len =3D length(\"$trunc_symbol\")
            if(substr(path, 0, home_len) =3D=3D home) {
                path =3D sprintf(\"~%s\", substr(path, home_len + 1))
            }
            path_len =3D length(path)
            if (path_len > max_len) {
                path =3D sprintf(\"%s%s\", \"$trunc_symbol\", substr(path, =
path_len + sym_len - max_len + 1))
            }
            print path
    }")
    OLDPWD=3D${PWD}
    fi
}

This is called via a build_prompt() function in my .bashrc. I guess I'll ec=
ho
out some variables there and see what's happening.

FTR this did work, and then I updated bash in ports.

Mike
--=20
Michael P. Soulier <msoulier@digitaltorque.ca>
"Any intelligent fool can make things bigger and more complex... It takes a
touch of genius - and a lot of courage to move in the opposite direction."
--Albert Einstein

--b5gNqxB1S1yM7hjW
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.11 (GNU/Linux)

iD8DBQFLAzHkKGqCc1vIvggRAlTYAKCyQTKhgNE5JrnrUvUx/1UwNQ86SACgs9e1
1GAWmhp3aktW7PWrOZG9uF8=
=KXWI
-----END PGP SIGNATURE-----

--b5gNqxB1S1yM7hjW--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20091117232940.GB6951>