]> snippets.scripts.mit.edu Git - Scripts/git/.git/blame - bash/newline-fix.bash
kdo: Upstream krb5 now supports kswitch
[Scripts/git/.git] / bash / newline-fix.bash
CommitLineData
bbe6be47
AK
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
3#
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
10# middle of a line.
11#
12# Copyright © 2010 Anders Kaseorg <andersk@mit.edu>
13#
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.
18#
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.
23#
24# Usage: Source this file from your ~/.bashrc.
25
26show_no_lf () {
27 tput -S <<NOLF && echo -n '<no LF>' && \
28 tput -S <<SPSP && echo -n ' ' && \
29 tput -S <<EOF
30sc
31tbc
32cr
33cuf 8
34hts
35rc
36setaf 1
37rev
38NOLF
39sgr0
40ht
41sc
42tbc
43cr
44$(for ((i=8; i<=320; i+=8)); do echo cuf 8; echo hts; done)
45rc
46SPSP
47cr
48el
49EOF
50}
51
52show_no_lf="$(show_no_lf)" && \
53PROMPT_COMMAND="echo -n \"\$show_no_lf\" >&2;$PROMPT_COMMAND"