1 # newline-fix.bash: Force the bash prompt to start after a newline
2 # http://snippets.scripts.mit.edu/gitweb.cgi/.git/blob/HEAD:/bash/newline-fix.bash
4 # Some commands don’t print a newline at the end of their output, or
5 # take long enough to return that you’ve already typed part of the
6 # next command. Either causes bash to start its prompt in the middle
7 # of a line, which confuses it. This script sets $PROMPT_COMMAND to
8 # echo a magic sequence of terminal commands that will display a red
9 # “<no LF>\n” before the prompt if it would otherwise start in the
12 # Copyright © 2010 Anders Kaseorg <andersk@mit.edu>
14 # This program is free software: you can redistribute it and/or modify
15 # it under the terms of the GNU General Public License as published by
16 # the Free Software Foundation, either version 2 of the License, or
17 # (at your option) any later version.
19 # This program is distributed in the hope that it will be useful, but
20 # WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 # General Public License for more details.
24 # Usage: Source this file from your ~/.bashrc.
27 tput -S <<NOLF && echo -n '<no LF>' && \
28 tput -S <<SPSP && echo -n ' ' && \
44 $(for ((i=8; i<=320; i+=8)); do echo cuf 8; echo hts; done)
52 show_no_lf="$(show_no_lf)" && \
53 PROMPT_COMMAND="echo -n \"\$show_no_lf\" >&2;$PROMPT_COMMAND"