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


Click here to return to the 'Saving PS1, don't change it :)' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Saving PS1, don't change it :)
Authored by: cheako on Sep 15, '03 05:43:33AM

This is what I have...

echo $PROMPT_COMMAND | grep -qe 'How many characters' || {
PROMPT_COMMAND=${PROMPT_COMMAND:+$PROMPT_COMMAND';
'}' {
# How many characters of the $PWD should be kept;
if [ "$lastPWD" != "$PWD" ];
then lastPWD="$PWD";
tmpPWD="$(echo -n "$PWD" |
sed -e '\''s:^'\''"$HOME"'\'':~:'\'')";
pwd_length=41;
pwd_prefixlength=11;
if [ $(echo -n "$tmpPWD" | wc -c) -gt $pwd_length ];
then newPWD="$(echo -n "$tmpPWD" |
sed -e '\''s:\(.\{'\''$pwd_prefixlength'\''\}\).*\(.\{'\''$((
$pwd_length - $pwd_prefixlength - 2 ))'\''\}\):\1..\2:'\'')";
else newPWD="$tmpPWD";
fi;
unset pwd_length pwd_prefixlength;
fi; # tmpPWD is not newPWD;
}'; # Out of singel quoted string hell.
# Export is not needed, but PS1 is and this will be used there.
export newPWD="$(echo -n "$PWD" | sed -e 's:^'"$HOME"':~:')"
# Force newPWD update.
lastPWD=..Yo..
}; # grep for 'How many characters' in PROMPT_COMMAND;

# All of this should allready be set to a good default, make them better.
[ "$PRO_UID" ] || PRO_UID=$(id -u)
if [ "$PRO_UID" -eq 0 ]
then PS1='\[\017\]\h:\[$newPWD\]\$ '
else PS1='\[\017\]\u@\h:\[$newPWD\]\$ '
fi
unset PRO_UID

# The \017 fixes the \016 bug :) echo -e '\016' for deatails :P



[ Reply to This | # ]