Search code examples
gitbashzshprompt

bash/zsh prompt displaying Git repository data right-aligned


I saw this in a Github video and would like the same right-aligned prompt in my shell.

How can I accomplish it?

or even better

Which prompt is used here?

enter image description here


Solution

  • You do this by setting the RPROMPT zsh variable. Example: to display the current time,

    RPROMPT='$(date +%T)'
    

    Make sure the promptsubst option is set by looking at the output of setopt. If it isn't, use setopt promptsubst in your .zshrc or equivalent.

    In your case, use the appropriate git command telling you the branch.

    For the gory details, read man zshmisc, especially the section EXPANSION OF PROMPT SEQUENCES.