Bash – A status bar at bottom of terminal in place of PS1

bashprompttmux

It occurred to me that when I'm doing stuff in the terminal my PS1 is repeated several times for each command. My PS1 includes CWD and git branch so it can get reasonably long.

Is there a way I can set my PS1 to just a $ dollar symbol, but move that other information into a 'status bar' or just keep it out the way at the bottom of the terminal? Much like tmux's status bar, but with those bits that usually form part of my prompt.

Ideally, I'd like a solution that just involves changing my .bashrc, but any solution would work. I did a bit of googling and found a git branch thing for tmux (but no CWD / other bits) and a really flakey 'status bar with time in' that didn't really work.

Example of issue:
enter image description here

Best Answer

This proposal should be read as a "proof of concept", not necessarily a turnkey solution. May need to be refined / adapted.

You seem to use console_codes anyhow in your PS1 so some extended usage might be allowed. For a "status bar" to appear at the bottom of the screen no matter how that was resized before, the LINES shell variable can be used, as well as some shell integer arithmetics, to shrink the scrolling region, save / restore the cursor location, and print to the bottom of the screen. Try

CSI=$'\e'"["
PS1="\[${CSI}s${CSI}1;$((LINES-1))r${CSI}$LINES;1f\u:YourOutputGoesHere:\w${CSI}K${CSI}u\]>"

There are known caveats when dealing with the PS1 shell variable and function codes which haven't necessarily been considered here but covered in e.g. other threads, search in these fora and incorporate if need be.

Related Question