Hello @romkatv, thanks for building powerlevel10k. Been loving this!
Branch names in several repositories which I work in are loooooong (longer than the one in the image at times)

This eats up all my space on prompt. I see that powerlevel9k has a feature to truncate branch names. Is there similar feature in powerlevel10k?
https://github.com/Powerlevel9k/powerlevel9k/pull/798
I tried adding powerlevel9k shortening config to .zshrc and sourcing it, and, that doesn't seem to work. (Did this with the hope of powerlevel10k honoring powerlevel9k configs)
POWERLEVEL9K_VCS_SHORTEN_LENGTH=8
POWERLEVEL9K_VCS_SHORTEN_STRATEGY=truncate_middle
In Powerlevel9k you need to define both POWERLEVEL9K_VCS_SHORTEN_LENGTH and POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH to enable branch shortening.
This logic is identical in Powerlevel10k. If you have a working Powerlevel9k config that utilizes branch shortening, you'll get the same results with this config if you switch to Powerlevel10k.
However, since you are using a config generated by the configuration wizard, your Git prompt segment is assembled within your config and it doesn't honor POWERLEVEL9K_VCS_SHORTEN_LENGTH or POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH. To configure shortening, open ~/.p10k.zsh and search for 32. This is basically POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH and you can change it to something smaller. There is also 12 in a couple of places on the next line. That's the equivalent of POWERLEVEL9K_VCS_SHORTEN_LENGTH.
The advantage of ~/.p10k.zsh is that you have a lot more freedom w.r.t. how you shorten your branches. If in your company branches follow certain rules, you can take advantage of them in order to shorten branches without too much information loss. For example, you can always drop the leading IND-XXX-, or the trailing -POC, or both. Or the other way around -- only leave those parts and drop the middle.
I can also highly recommend two-line prompt. Vertical space is cheap, and it's a good deal to get the full terminal width for typing your commands in exchange for one line per prompt. In addition, it's really nice when all your commands start from the same column. Makes it much easier to read your history or your current prompt. You can also spread your right prompt segments over two lines instead of cramming all of them on a single line.
Lastly, I see that you have an unusually high number of unstaged Git changes. Does that !1495 match what you see in the output of git status? If it doesn't, this is likely a bug and I'd like to fix it if you could provide more info. If you indeed have locally modified or deleted 1495 files, you might want to search for MAX_NUM in ~/.p10k.zsh and change the value to 99. This will change your prompt so that it shows at most !99, which for practical purposes might be as good as the real number since both essentially mean "many". The benefit is that your prompt will be faster.
Thank you for the detailed response, @romkatv. Appreciate it!
You're right, I had totally missed defining POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH. I modified my ~/.p10k.zsh based on your feedback and it works like a charm. I also choose the two-line prompt, great tip!
Regarding the high number of unstaged Git changes, I had moved several directories around and that caused these many changes. It matches my git status too. I did update my MAX_NUM to be 99. Not sure if you've seen this feature on chrome on phones where after 99 tabs the counter just becomes :D - it's pretty funny and cool.
Also, while modifying the max line length for branch, I had to manually adjust the shortened length. Might be cool to have a default way to identify the lengths? Or have the configure tool help you do it? Not sure if it is an overkill.
If MAX_LEN=32, DEF_SHORT_LEN=round(MAX_LEN/2).
And, strip -> [1, (DEF_SHORT_LEN/2)-2] + ... + [(DEF_SHORT_LEN/2)-1, 1]
Just throwing an idea out there.
Thank you for the detailed response, @romkatv. Appreciate it!
You're right, I had totally missed defining
POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH. I modified my~/.p10k.zshbased on your feedback and it works like a charm. I also choose the two-line prompt, great tip!Regarding the high number of unstaged Git changes, I had moved several directories around and that caused these many changes. It matches my
git statustoo. I did update myMAX_NUMto be 99. Not sure if you've seen this feature on chrome on phones where after 99 tabs the counter just becomes:D- it's pretty funny and cool.Also, while modifying the max line length for branch, I had to manually adjust the shortened length. Might be cool to have a default way to identify the lengths? Or have the configure tool help you do it? Not sure if it is an overkill.
Questions in the configuration wizard have high costs as all users will have to go through them. If the default works for 99% of the user base, I prefer not to ask for the preference and to let the 1% apply edits directly in ~/.p10k.zsh. Comments in that file are supposed to make simple edits possible without having to understand the minutia details of ZSH scripting. I've committed https://github.com/romkatv/powerlevel10k/commit/9a5abe8185870df5e41e5506253fc9575d541dc9 to help with branch shortening edits.
If
MAX_LEN=32,DEF_SHORT_LEN=round(MAX_LEN/2).
And, strip ->[1, (DEF_SHORT_LEN/2)-2]+...+[(DEF_SHORT_LEN/2)-1, 1]Just throwing an idea out there.
This might be more difficult to edit. Constants -2 and -1 in this implementation are tunable parameters but it's not obvious from the code how they will affect the results. It's also more difficult to see how to retain just the suffix (or prefix) and drop the rest.
The default config works as if the following parameters were defined:
POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH=32
POWERLEVEL9K_VCS_SHORTEN_LENGTH=12
POWERLEVEL9K_VCS_SHORTEN_STRATEGY=truncate_middle
Note that 12 is quite a bit less than 32 / 2. This is intended. Shortening just to save 1 or 2 characters is not a good trade-off, so by default shortening will happen only if it can save at least 8 characters. How much to leave from the prefix and the suffix is easy to configure, and the effect of 12 in both cases is obvious to the reader. I value these properties.
P.S.
Consider installing the recommended font and to running p10k configure again. With "lean" style and "few" icons you'll get prompt a little bit shorter than you have now, without any loss of information. For example, Py will become an icon, saving one character. It'll look a bit nicer, too.
Most helpful comment
In Powerlevel9k you need to define both
POWERLEVEL9K_VCS_SHORTEN_LENGTHandPOWERLEVEL9K_VCS_SHORTEN_MIN_LENGTHto enable branch shortening.https://github.com/Powerlevel9k/powerlevel9k/blob/d1fbc1b889f63f6ea3e9672b7069133493ccab8a/functions/vcs.zsh#L54
This logic is identical in Powerlevel10k. If you have a working Powerlevel9k config that utilizes branch shortening, you'll get the same results with this config if you switch to Powerlevel10k.
However, since you are using a config generated by the configuration wizard, your Git prompt segment is assembled within your config and it doesn't honor
POWERLEVEL9K_VCS_SHORTEN_LENGTHorPOWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH. To configure shortening, open~/.p10k.zshand search for32. This is basicallyPOWERLEVEL9K_VCS_SHORTEN_MIN_LENGTHand you can change it to something smaller. There is also12in a couple of places on the next line. That's the equivalent ofPOWERLEVEL9K_VCS_SHORTEN_LENGTH.The advantage of
~/.p10k.zshis that you have a lot more freedom w.r.t. how you shorten your branches. If in your company branches follow certain rules, you can take advantage of them in order to shorten branches without too much information loss. For example, you can always drop the leadingIND-XXX-, or the trailing-POC, or both. Or the other way around -- only leave those parts and drop the middle.I can also highly recommend two-line prompt. Vertical space is cheap, and it's a good deal to get the full terminal width for typing your commands in exchange for one line per prompt. In addition, it's really nice when all your commands start from the same column. Makes it much easier to read your history or your current prompt. You can also spread your right prompt segments over two lines instead of cramming all of them on a single line.
Lastly, I see that you have an unusually high number of unstaged Git changes. Does that
!1495match what you see in the output ofgit status? If it doesn't, this is likely a bug and I'd like to fix it if you could provide more info. If you indeed have locally modified or deleted 1495 files, you might want to search forMAX_NUMin~/.p10k.zshand change the value to99. This will change your prompt so that it shows at most!99, which for practical purposes might be as good as the real number since both essentially mean "many". The benefit is that your prompt will be faster.