5

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

John Hunt
  • 848

2 Answers2

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.

RudiC
  • 8,969
  • 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 05 '18 at 11:35
  • Thanks for doing a better (and quicker) search than I did. I'll incorporate that \[ and \]. – RudiC Oct 05 '18 at 11:49
0

There is a tmux plugin I have been working on that kind of does this. Have a look:

https://github.com/casonadams/tmux-space-theme

or if you want to just add a few things to your ~/.tmux.conf

home="#(if [[ $HOME == #{pane_current_path} ]]; then echo \"~\" ; else echo #{b:pane_current_path}; fi)"

path="#($(tmux showw -v @show-full-window-path) == true && echo \"$(echo #{pane_current_path} | awk '{print \"~\"$1}' | cut -d/ -f-1,4-)\" || echo \"$home\")"

git_status="#(cd #{pane_current_path}; git status --ignore-submodules -sb | head -n1 | tr -d \"# \" | cut -f1 -d\".\")"


# Then use the vars where you want them.

set-option -g status-right " $git_status "
set-window-option -g window-status-current-format " $path "

One can also add setw -q @show-full-window-path true to show full path also.