I have something like this in my login script that keeps $foo in the top right of my terminal. It works, but with a caveat. If I type a really long command it doesn't wrap. (Well, it'll wrap if it's more than two lines long, but the 2nd line overwrites the 1st line, if that makes sense.)
Anyone know how I can make bash wrap (i.e. insert newline) at $POS? Or even at $COLUMNS?
trunc_pwd () { # See http://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x783.html
local pwdmaxlen=50 # Number of $PWD chars to keep
local trunc_symbol="<" # Prepend to truncated $PWD
if (( ${#PWD} > $pwdmaxlen )); then
local pwdoffset=$(( ${#PWD} - $pwdmaxlen ))
echo "${trunc_symbol}${PWD:$pwdoffset:$pwdmaxlen}"
else
echo ${PWD} | sed "s%^${HOME}%~%g"
fi
}
foo="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
get_pos ()
{
POS=$((COLUMNS-(${#foo}+4)))
}
if [[ ${PS1} ]]; then
PROMPT_COMMAND='get_pos ; echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:$(trunc_pwd)"; echo -ne "\007"'
export PS1="\u@\h \W \$ \[\e[s\]\[\e[1;\$(echo -n \${POS})H\]$foo\[\e[u\]"
fi