bash prompt update lagging
Michael P. Soulier
msoulier at digitaltorque.ca
Wed Nov 18 02:07:26 UTC 2009
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 at 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/freebsd-questions/attachments/20091118/69f02156/attachment.pgp
More information about the freebsd-questions
mailing list