Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Correction to original post?' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Correction to original post?
Authored by: clh on Dec 31, '01 04:16:36AM

For the solution in the original post to work, I believe you need to set PS1 *inside* the prompt_command function.

The final lines of the function should read

...
if [ $(echo -n $PWD | wc -c | tr -d " ") -gt $pwd_length ]
then newPWD="$(echo -n $PWD | sed -e "s/.*(.{$pwd_length})/1/")"
else newPWD="$(echo -n $PWD)"
fi
PS1="[u@h:$newPWD]$ " ## <-- add this line to recompute PS1
}

Another solution, which doesn't require burying the assignment of PS1 inside a function, is to modify prompt_command as follows:

...
if [ $(echo -n $PWD | wc -c | tr -d " ") -gt $pwd_length ]
then newPWD="$(echo -n $PWD | sed -e "s/.*(.{$pwd_length})/1/")"
else newPWD="$(echo -n $PWD)"
fi
echo $newPWD ## <-- "return" the newly-computed CWD
}

Then set PS1 as follows

PS1="u@h:$(prompt_command)$ " ## <-- invokes prompt_command and inserts CWD

You don't need to use the PROMPT_COMMAND variable with this method.

Well, I'm new to this forum and I haven't learned how achieve WYSIWYGedness, so I'm sure this will be missing scads of backslashes when you read it on the web. But anyway, I *think* the original post was not quite correct.

semicolon hyphen close-parenthesis



[ Reply to This | # ]