gitstatus icon indicating copy to clipboard operation
gitstatus copied to clipboard

How to show full branch name?

Open chiphogg opened this issue 1 month ago • 2 comments

(I know the project is close-to-unmaintained, but I'm hoping it will be very quick to point me in the right direction for how to solve this.)

I love this project, but the branch name abbreviation drives me absolutely batty. The way we use git at work, all my branches start with the same chiphogg/ prefix, which thus contains zero information. And the end of the branch often includes #PROJ-1234 suffixes, which all kinda blend together. The real useful information is in the middle!

I want to configure the prompt to print the full branch name, always, no matter how long it is. Which pathway(s) are available to me?

  1. Follow the copy-and-modify approach at the end of the bash section
  2. Provide a PR to add a new environment variable that a user can set, to gate what I assume is the truncation code
  3. Fork this project and delete the truncation code
  4. ...something else?

Thanks in advance!

chiphogg avatar Dec 03 '25 19:12 chiphogg

1 is a good option, and so is 3.

romkatv avatar Dec 03 '25 19:12 romkatv

Thank you!

Is (1) even an option, if the contents of where get unconditionally clobbered by the truncation code? I assume not --- so, therefore, I assume that (3) is the way to go.


By the way, the act of choosing (3) means that also doing (2) would be a very small marginal effort. So, I'll probably put up a PR as well after I fork it. Given the status of this repo, I have no expectation that it will be merged... but, there's an outside chance that the PR ends up being both simple and desirable enough that you might merge it anyway.

And if not, then the PR will end up linked to this issue, so others who want this functionality will be able to stumble upon it.

chiphogg avatar Dec 03 '25 21:12 chiphogg

For (1), you can start with this:

source ~/gitstatus/gitstatus.plugin.sh

function my_set_prompt() {
  PS1='\w'

  if gitstatus_query && [[ "$VCS_STATUS_RESULT" == ok-sync ]]; then
    if [[ -n "$VCS_STATUS_LOCAL_BRANCH" ]]; then
      PS1+=" ${VCS_STATUS_LOCAL_BRANCH//\\/\\\\}"  # escape backslash
    else
      PS1+=" @${VCS_STATUS_COMMIT//\\/\\\\}"       # escape backslash
    fi
    (( VCS_STATUS_HAS_STAGED"    )) && PS1+='+'
    (( VCS_STATUS_HAS_UNSTAGED"  )) && PS1+='!'
    (( VCS_STATUS_HAS_UNTRACKED" )) && PS1+='?'
  fi

  PS1+='\n\$ '

  shopt -u promptvars  # disable expansion of '$(...)' and the like
}

gitstatus_stop && gitstatus_start
PROMPT_COMMAND=my_set_prompt

Modify my_set_prompt as you like.

romkatv avatar Dec 04 '25 06:12 romkatv