hey folks,
I'm, trying to configure my spaceship prompt to put the context-dependant sections (git, docker etc) on the right prompt so that my left prompt remains a static(ish) width. Unfortunately, the right prompt gets rendered on the second line, where i actually enter commands.
It's not the end of the world by any means, but I was hoping both parts would be on the same line. I think I saw it render that way before, but I'm not really sure.
Thanks!
We discussed this with PR that implemented RPROMPT at https://github.com/denysdovhan/spaceship-prompt/pull/168#issuecomment-314333800.
there is a risk: the rprompt disappears if it overlaps with anything from the left prompt, so if your terminal width is small or you pack too much into the rprompt, you won't see it at all.
https://github.com/denysdovhan/spaceship-prompt/pull/168#issuecomment-314571354
We could reconsider this with next major release.
Ah, yeah that could be a concern in a general case, but in my use case (left prompt is static width), they can only collide if right prompt is very long or terminal is very narrow. Ill take a look at the rprompt code, maybe I can figure out a way to make it work nicely in my case, and try to generalize it after.
< Spitballing>
Although... If the right prompt was always considered 'low priority', then maybe having it disappear if there's not enough width for it could be considered a "feature". Maybe it could be smart enough to collapse to just a count of the hidden sections in those cases.
Last suggestion about hiding it while there's not enough space available and collapsing it sounds good. But that would still require calculation on each prompt redraw right ? If we can make that happen without considerable performance issue, this would be awesome.
Looking forward for the awesome PR :smile:
It seems that powerlevel9k uses another trick, which is not perfect either.
if [[ "$P9K_RPROMPT_ON_NEWLINE" != true ]]; then
# The right prompt should be on the same line as the first line of the left
# prompt. To do so, there is just a quite ugly workaround: Before zsh draws
# the RPROMPT, we advise it, to go one line up. At the end of RPROMPT, we
# advise it to go one line down. See:
# http://superuser.com/questions/357107/zsh-right-justify-in-ps1
RPROMPT_PREFIX='%{'$'\e[1A''%}' # one line up
RPROMPT_SUFFIX='%{'$'\e[1B''%}' # one line down
The right prompt won't disappear when it overlaps with left prompt according to my experience. But the drawback is that part of the prompt content will remain above current prompt after you resize ur terminal.
SPACESHIP_RPROMPT_ORDER=(
rprompt_prefix
# line_sep # Line break
exit_code # Exit code section
exec_time # Execution time
jobs # Background jobs indicator
time # Time stamps section
rprompt_suffix
)
# borrowed from __p9k_prepare_prompts
# RPROMPT_PREFIX='%{'$'\e[1A''%}' # one line up
# RPROMPT_SUFFIX='%{'$'\e[1B''%}' # one line down
spaceship_rprompt_prefix() {
echo -n '%{'$'\e[1A''%}'
}
spaceship_rprompt_suffix() {
echo -n '%{'$'\e[1B''%}'
}
FYI: The approach chosen by powerlevel9k has a few issues:
Most helpful comment
It seems that powerlevel9k uses another trick, which is not perfect either.
https://github.com/bhilburn/powerlevel9k/blob/06ed821ded11948c5972b2177ab2019a59c36b39/generator/default.p9k#L392-L400
The right prompt won't disappear when it overlaps with left prompt according to my experience. But the drawback is that part of the prompt content will remain above current prompt after you resize ur terminal.