Comments (3)
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.
@agkozak Thanks for the great explanation! Works well, thanks for making this so customizable.
from agkozak-zsh-prompt.
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)
- Is is possible to add Powerline Font character in prompt? HOT 13
- `cat` alias breaks `async` function HOT 7
- AGKOZAK_MULTILINE not simpatico with AGKOZAK_LEFT_PROMPT_ONLY HOT 8
- Show execution time above a given threshold HOT 13
- Add virtualenv indicator HOT 11
- Printing error on non-root android termux HOT 9
- Removing exit status does not work HOT 2
- [Question] Can an additional command be executed to be shown on the shell? HOT 2
- FR: zsh `promptinit` API support HOT 6
- Request: display pipestatus when any exit codes are non-zero HOT 5
- Ctrl + Left/Right to jump between words instead of vi/normal mode? HOT 5
- Finished background jobs don't update prompt HOT 5
- Long branch names in git cannot be concatenated HOT 7
- Under some conditions, when typing next cmd during previous cmd execution, prompt formatting gets mangled HOT 8
- Request: parameters for custom pre- and post- CWD chars HOT 1
- Support for distrobox
- Setting AGKOZAK_SHOW_STASH=0 disables all git symbols HOT 3
- OSC 133 integration HOT 2
- Cmd + k to refresh prompt HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from agkozak-zsh-prompt.