commit a69f6c9837e03b3c691ec4c55c7ecd833a15cb65 parent f763745624fe8c0780e0d2997041d3627926f071 Author: KΓ©vin Le Gouguec <kevin.legouguec@gmail.com> Date: Wed, 1 Mar 2017 07:39:08 +0100 Split prompt into two lines User/host/working-directory/Git status go on the first line; the "prompt" line only contains the prompt symbol and the previous command's error code. Also fill the rest of the line when a command does not end with a newline. Diffstat:
| M | .bash_prompt | | | 79 | +++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------- |
1 file changed, 53 insertions(+), 26 deletions(-)
diff --git a/.bash_prompt b/.bash_prompt @@ -122,22 +122,6 @@ __set-prompt () PS1+=$(__fontify "${last_status} " bold red) fi - PS1+=$(__fontify '\u' green) - - if __show-hostname - then - PS1+=$(__fontify '@' dim) - PS1+=$(__fontify '\H' bold green) - fi - - PS1+=$(__fontify : dim) - PS1+=$(__fontify '\w' bold blue) - - if [ ${PS1_SHOWGITSTATUS} ] - then - PS1+=$(__fontify "$(__git_ps1 '(%s)')" red) - fi - PS1+=$(__fontify '\$' dim) PS1+=' ' @@ -161,30 +145,73 @@ __current-column () fi } -__draw-rule () +__fill-line () { - local rule='' - local column=$(__current-column) + local char=$1 + shift + + local line='' - for ((i=column; i<=COLUMNS; i++)) + for ((i=$(__current-column); i<COLUMNS; i++)) do - rule+=β + line+=${char} done - # If we do not add a newline, the prompt will be shoved offscreen - # when autowrap is off. - rule+='\n' + # If we do not add a newline, whatever comes after will be shoved + # offscreen when autowrap is off. + line+='\n' + + __fontify ${line} $@ +} + +__draw-rule () +{ + __fill-line β dim +} + +__finish-line () +{ + __fill-line / dim red +} + +__write-context () +{ + local context='' + + context+=$(__fontify "${USER}" green) + + if __show-hostname + then + context+=$(__fontify '@' dim) + context+=$(__fontify "${HOSTNAME}" bold green) + fi + + context+=$(__fontify : dim) + context+=$(__fontify "${PWD/~/\~}" bold blue) - __fontify ${rule} dim + if [ ${PS1_SHOWGITSTATUS} ] + then + context+=$(__fontify "$(__git_ps1 '(%s)')" red) + fi + + echo -n "${context} " } __refresh-terminal () { local last_status=$? + local last_column=$(__current-column) __set-title - __set-prompt ${last_status} + + if [ ${last_column} -ne 1 ] + then + __finish-line + fi + + __write-context __draw-rule + __set-prompt ${last_status} }