Most of the time the output of a command ends with the newline character. But sometimes it does not, so the next shell prompt is printed in the same line together with the output.
root@hostname [~] # echo -n hello
helloroot@hostname [~] #
I've always found that very annoying.
Now, I could just add a "\n" at the beginning of the the PS1 variable, but most of the time that will print one extra line I dont need.
Is it possible to know whether the last command's output ended with a newline or not?
(Thanks to Dennis)
PS1='$(printf "%$((`tput cols`-1))s\r")\u@\h [\w]\$ '