GithubHelp home page GithubHelp logo

Comments (3)

agkozak avatar agkozak commented on July 23, 2024

Thanks for asking!

Short answer

AGKOZAK_CUSTOM_SYMBOLS=(
  '%F{yellow}▾%f%F{green}▴%f' # Diverged
  '%F{yellow}▾%f'             # Behind
  '%F{green}▴%f'              # Ahead
  '%F{green}•%f'              # Unstaged
  '%F{red}•%f'                # Deleted
  '%F{red}•%f'                # Modified
  '%F{red}•%f'                # Renamed
  '%F{yellow}•%f'             # Untracked
  '%F{red}*%f'                # Stashed
)

AGKOZAK_CUSTOM_RPROMPT='%(3V.%F{yellow}(%6v%f%(7V. ${psvar[7]}.)%F{yellow}%)%f.)'

Long answer

The reason why what you're trying to do isn't working out of the box is because, out of the box, the prompt strings use a simple shorthand for the $psvar array elements that store important prompt information. ${psvar[3]}, for example, stores things like (master ?), and the prompt string contains the shorthand %3v to display it.

Unfortunately, those prompt expansion shorthands don't handle things like color escape sequences well. If we use ${psvar[3]} instead of %3v, though, we can work around that shortcoming of the shell. At the risk of sounding like my high school geometry teacher, for educational purposes, I'll show you first how to almost achieve what you want, and then I'll show you the slightly more complicated solution that should give you exactly what you need.

To start with, you'll need to use the $AGKOZAK_CUSTOM_RPROMPT string to override the default right prompt string. You may start by reproducing the default behavior with the following code:

# Git status
AGKOZAK_CUSTOM_RPROMPT='%(3V.%F{yellow}%3v%f.)'

To resolve the problem of escape sequences not making it through, replace %3v with ${psvar[3]}:

AGKOZAK_CUSTOM_RPROMPT='%(3V.%F{yellow}${psvar[3]}%f.)'

That change alone should achieve almost what you want. But since the overall color of the Git status indicator is only set once, your customization will result in the closing parenthesis being the default text color; basically, you're saying "foreground yellow on," "open parenthesis," "branch name," "new custom foreground color on + custom symbols + foreground color off," "close parenthesis," "foreground color off." That's not quite right, so we need to rewrite the prompt indicator to be a little more nuanced:

AGKOZAK_CUSTOM_RPROMPT='%(3V.%F{yellow}(%6v%f%(7V. ${psvar[7]}.)%F{yellow}%)%f.)'

That's the equivalent of saying "If there's a Git status (%(3V.), turn on yellow, print an open parenthesis, print just the branch name (%6v), turn off the foreground color; if there are Git symbols to print (%(7V.), print them -- including color escape sequences (${psvar[7]}) -- then turn yellow back on, print a close parenthesis (%)), and turn off the foreground color."

Eventually I'll probably make it easier to do this with more minimal custom code.

from agkozak-zsh-prompt.

brandoniffert avatar brandoniffert commented on July 23, 2024

@agkozak Thanks for the great explanation! Works well, thanks for making this so customizable.

from agkozak-zsh-prompt.

yacoob avatar yacoob commented on July 23, 2024

Apologies for resurrecting this old bug, but I'd like to turn this into a feature request :)

I wanted to turn @ in psvar[1] red. Currently, in order to achieve that, I'd need to construct an entire AGKOZAK_CUSTOM_PROMPT by myself, based on what's the default - and then keep track of it, as it changes over the time upstream.

Any chance for that functionality? :)

Thanks!

from agkozak-zsh-prompt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.