bash-git-prompt icon indicating copy to clipboard operation
bash-git-prompt copied to clipboard

Branch names are interpreted as globs before being printed

Open ghost opened this issue 7 years ago • 3 comments

I wanted my prompt to be relatively short/clean, so I opted for a one-line theme. Now, I was also a bit annoyed that the branch names I dealt with were always so long. Hence, I added a little sed call to shorten some common branch names. While doing that I also defined *m for "master" (my added sed call is in gitstatus.sh, right before the final printf).

However, now, when I am in a repo that contains files that match the glob *m, what will be displayed are the file names that match said glob instead of the branch name.

ghost avatar Feb 21 '18 11:02 ghost

You should take a look at the function replaceSymbols:

function replaceSymbols() {
  # Disable globbing, so a * could be used as symbol here
  set -f

  if [[ -z ${GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING} ]]; then
    GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING=L
  fi

  local VALUE=${1//_AHEAD_/${GIT_PROMPT_SYMBOLS_AHEAD}}
  local VALUE1=${VALUE//_BEHIND_/${GIT_PROMPT_SYMBOLS_BEHIND}}
  local VALUE2=${VALUE1//_NO_REMOTE_TRACKING_/${GIT_PROMPT_SYMBOLS_NO_REMOTE_TRACKING}}
  local VALUE3=${VALUE2//master/*m}

  echo ${VALUE3//_PREHASH_/${GIT_PROMPT_SYMBOLS_PREHASH}}

  # reenable globbing symbols
  set +f
}

It is used to replace all symbols in the prompt - you could add your sed there. I tried it as seen above and it changed the master branch name to *m. I used bash substitution on the line defining VALUE3. @sknorr

ogr3 avatar Feb 21 '18 15:02 ogr3

Thanks for the workaround! However, isn't it sort of evil anyway that branch names can be interpreted as globs? Sure, git checkout -b does not actually allow creating branches with * in them but if it did or you somehow used plumbing commands for this (no, I haven't tried)?

ghost avatar Feb 22 '18 11:02 ghost

Good question,

Git branches does not allow the usual wildcard characters:

https://stackoverflow.com/questions/28183115/rules-when-naming-git-branches/28183192#28183192

So I don't know if this is a real potential problem.

ogr3 avatar Feb 22 '18 13:02 ogr3