4

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

  • For git status in the tmux status line see this superuser answer. – meuh Oct 5 '18 at 18:50
3

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.

  • 1
    With control codes that don't add to the actual length of the prompt, the main issue is that they need to be wrapped within \[ and \]. So PS1="\[${CSI}s${CSI}1;$((LINES-1))r$CSI$LINES;1g\]\u..." if I got that right. See e.g. this and maybe this. The question about puppet is mostly about the trouble with quoting the assignment for multiple shells interpreting it. – ilkkachu Oct 5 '18 at 11:35
  • Thanks for doing a better (and quicker) search than I did. I'll incorporate that \[ and \]. – RudiC Oct 5 '18 at 11:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.