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

Add support for zsh

Open geksiong opened this issue 5 years ago • 6 comments

This is my attempt to make bash-git-prompt work with zsh, by modifying the bash scripts without introducing additional scripts. It assumes the zsh colors module is loaded.

Disclaimer: I'm new to zsh scripting as I recently switched to zsh. It seems to work fine on my system so far, but may need more testing.

ps. It still works with bash

geksiong avatar Apr 28 '20 15:04 geksiong

I'm also very new to zsh, but couldn't seem to get this to work; am I doing something incorrectly? Here's the excerpt from my ~/.zshrc:

autoload -U colors && colors
  
if [ -f "${HOME}/Projects/bash-git-prompt/gitprompt.sh" ]; then
    __GIT_PROMPT_DIR="${HOME}/Projects/bash-git-prompt"
    source "${HOME}/Projects/bash-git-prompt/gitprompt.sh"
fi

where ${HOME}/Projects/bash-git-prompt is where I have your zsh-support branch checked out.

MPLew-is avatar May 14 '20 09:05 MPLew-is

Because bash-git-prompt sets $PROMPT_COMMAND which is specific to bash only, you need to add the following to get the prompt to take effect in zsh: precmd() { eval $PROMPT_COMMAND}

geksiong avatar May 15 '20 10:05 geksiong

Thanks, I was able to get it displaying, and have submitted a pull request into your fork to correct a few issues I found. In addition, one remaining issue that I'm seeing is that my prompt doesn't expand ${GIT_BRANCH}:

~/Projects/bash-git-prompt [${GIT_BRANCH}|✔] 

The root cause of this is the escaped \${GIT_BRANCH} in gitprompt.sh, and going through git blame it looks like this was introduced as a security fix. Removing the indirection (that is, changing \${GIT_BRANCH} to just ${GIT_BRANCH}) fixes the issue, but I do not know enough about the security issue that that fix was designed to prevent to know if that's a good fix.

MPLew-is avatar May 18 '20 23:05 MPLew-is

@magicmonty or @ogr3 do you know if it's safe to just leave ${GIT_BRANCH} unescaped on zsh? It looks like at least one level of evaluation is removed using the different shell, which might eliminate that issue entirely.

MPLew-is avatar May 18 '20 23:05 MPLew-is

I'm also interested in this feature! I've checked out your branch and works like a charm adding @MPLew-is snippet and precmd function at the end of .zshrc. It works like a charm! Thank you!

andruten avatar Sep 12 '20 06:09 andruten

what's the purpose of this PR? i think this project is a port for bash of https://github.com/olivierverdier/zsh-git-prompt , which provides support for customizing the zsh prompt for git. can you use that instead?

sandrotosi avatar Jan 01 '22 23:01 sandrotosi