Bash – Highlight current bash prompt line

bashprompt

I want the terminal to highlight the current bash prompt line.
The effect I'm trying to acheive is the same as in text editors where the current line with the cursor is highlighted.
Something like this:
enter image description here

Best Answer

If you're happy with highlighting only the prompt, then the following will apply reverse colors on whatever you have already in PS1:

PS1="\[\e[7m\]$PS1\[\e(B\e[m\]"

If you have a space at the end of the prompt (this is common practice) that you don't want to highlight:

PS1="[\e[7m]${PS1::-1}[\e(B\e[m] "

Some terminals, at least iTerm for macOS, have the option to set a "cursor guide". This is probably doing exactly what you want to achieve (I have exaggerated the guide in the picture, I usually have it much more transparent, and red, as in the second picture):

iTerm with green transparent cursor guide, running bash

The cursor guide has nothing to do with the shell and will be always be displayed, regardless of what you're doing (very faint red cursor guide on the line reading AC_CONF_AUX_DIR([build]), here shown in the vim editor):

iTerm with faint red cursor guide, running vim

Unfortunately I only run iTerm on macOS, so I don't know if there are terminal emulators out there that can do this for your particular Unix.

Related Question