Zsh right-justify in ps1

promptzsh

I'd like a multi-line zsh prompt with a right alined part, that will look something like this:

2.nate@host:/current/dir                                               16:00
->

I know about RPROMPT in zsh, but that has a right-aligned prompt opposite your normal prompt, which is on the same line of text as your typing.

Is there a way to have a right-aligned portion to the first line of a multi-line command prompt? I'm looking for either a directive in the PS1 variable that says 'right align now' or a variable that is to PS1 what RPROMPT is to PROMPT.

Thanks!

Best Answer

You will find a detailed answer and an example here. The idea is to write the line before PS1 using the precmd callback, use $COLUMNS, and a bit of math to calculate the position of the text on the right side of the screen. Knowledge of escape sequences will also help you with cursor positioning and colouring.

Another solution can be to use a theme from Oh My ZSH.

Related Question