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
[-- Attachment #1 --]
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=$1
local trunc_symbol="..."
if [ -z "$max_length" ]; then
max_length=20
fi
if [ "$PWD" != "$OLDPWD" ]; then
SHORT_PWD=$(awk "BEGIN {
path = ENVIRON[\"PWD\"]
home = ENVIRON[\"HOME\"]
home_len = length(home)
max_len = $max_length
sym_len = length(\"$trunc_symbol\")
if(substr(path, 0, home_len) == home) {
path = sprintf(\"~%s\", substr(path, home_len + 1))
}
path_len = length(path)
if (path_len > max_len) {
path = sprintf(\"%s%s\", \"$trunc_symbol\", substr(path, path_len + sym_len - max_len + 1))
}
print path
}")
OLDPWD=${PWD}
fi
}
This is called via a build_prompt() function in my .bashrc. I guess I'll echo
out some variables there and see what's happening.
FTR this did work, and then I updated bash in ports.
Mike
--
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
[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.11 (GNU/Linux)
iD8DBQFLAzHkKGqCc1vIvggRAlTYAKCyQTKhgNE5JrnrUvUx/1UwNQ86SACgs9e1
1GAWmhp3aktW7PWrOZG9uF8=
=KXWI
-----END PGP SIGNATURE-----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20091117232940.GB6951>
