Keep Git Branch Name Untruncated in Shell using p10k (Oh My Zsh theme)
Asked Answered
J

4

34

I'm using a Mac (Catalina), iTerm2, Oh My Zsh (https://ohmyz.sh/), and the p10k zsh theme (https://github.com/romkatv/powerlevel10k).

Currently my git branches are showing truncated names on iTerm2 (like davidb/my-kewl...branch) instead of the untruncted branch names, like:
davidb/my-kewl-feature-branch

How do I turn off git branch name truncating? I want the untruncated git branch names.

Per https://github.com/romkatv/powerlevel10k/issues/193, I'm unsure how to use the code below in my ~/.p10k.zs file to turn off git branch name truncating. I've already tried many combinations, including Google searches, and nothing worked.

POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH=32
POWERLEVEL9K_VCS_SHORTEN_LENGTH=12
POWERLEVEL9K_VCS_SHORTEN_STRATEGY=truncate_middle
Justitia answered 7/5, 2020 at 21:0 Comment(0)
A
78

As of July 2022, the line to delete is 400

(( $#branch > 32 )) && branch[13,-13]="…"  # <-- this line
Algia answered 2/2, 2021 at 4:7 Comment(8)
As of June 2022, the line to delete is 393Bashkir
As of July 2022, the line to delete is 400Cochlea
As of August 2022, the line to delete is 393. Specifically, git commit id: f9fd384d8d64022e24c83bb03ba69e415c7fa90e, which corresponds to a change on July 31, 2022.Adversaria
For those looking, the file you need to look is ~/.pk10.zsh, which is probably under {user}/.pk10.zshCheckerberry
For those looking for a shortcut, just type open ~/.pk10.zsh in your terminal. This will open the default editorSycophancy
like the comment above telling which line number, actually I am thinking we can use search :)Skindeep
Once do it, you should run source ~/.zshrcMaureenmaureene
The correct filename is ~/.p10k.zs (not ~/.pk10.zs as some have mentioned)Redress
J
42

I got the answer from the p10k zsh theme (https://github.com/romkatv/powerlevel10k) creator Roman on Gitter: https://gitter.im/powerlevel10k/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge

In ~/.pk10.zsh or ~/.p10k.zsh delete, or comment out, line 375 as shown in this Github repo file: https://github.com/romkatv/powerlevel10k/blob/459af1f2382ff53214bf9e4fc598b4e36fb8f8df/config/p10k-lean.zsh#L374

Line to Comment Out or Delete in Repo Link Above

(( $#where > 32 )) && where[13,-13]="…"

Thanks Roman!

Justitia answered 12/5, 2020 at 0:58 Comment(2)
Be great if it was an option during config.Operculum
Now the code has changed. Search for the string <-- this line instead, there are only 4 places. You might want to have a look at them all :)Wanitawanneeickel
H
5

For those who can't find the config file, the file is located in your home directory so do a cd ~/.p10k.zsh or vim ~/.p10k.zsh to edit the file directly. The file has all the informations about what each line does, so you just need to read the comments and you will probably find this:

  396     if [[ -n $VCS_STATUS_LOCAL_BRANCH ]]; then
  397       local branch=${(V)VCS_STATUS_LOCAL_BRANCH}
  398       # If local branch name is at most 32 characters long, show it in full.
  399       # Otherwise show the first 12 … the last 12.
  400       # Tip: To always show local branch name in full without truncation, delete the next line.
  401       (( $#branch > 32 )) && branch[13,-13]="…"  # <-- this line
  402       res+="${clean}${(g::)POWERLEVEL9K_VCS_BRANCH_ICON}${branch//\%/%%}"
  403     fi

As you see it states which line should be deleted to not have ellipsis prepended in the git branch name, in this current version line number 401.

Hartman answered 29/11, 2022 at 13:9 Comment(0)
R
0

in last may 2024 update it's here

.p10k.zsh line 396 ( note it's .. now , no more ... )

    if [[ -n $VCS_STATUS_LOCAL_BRANCH ]]; then
      local branch=${(V)VCS_STATUS_LOCAL_BRANCH}
      # If local branch name is at most 32 characters long, show it in full.
      # Otherwise show the first 12 .. the last 12.
      # Tip: To always show local branch name in full without truncation, delete the next line.
      (( $#branch > 32 )) && branch[13,-13]=".."  # <-- this line
      res+="${clean}${(g::)POWERLEVEL9K_VCS_BRANCH_ICON}${branch//\%/%%}"
    fi

Rosmunda answered 2/5 at 8:31 Comment(1)
@Alainlb Please change "mai 2024" to "May 2024" to fix a minor spelling error. Except for that, thanks for the update! I appreciate your work.Justitia

© 2022 - 2024 — McMap. All rights reserved.