bash-git-prompt
bash-git-prompt copied to clipboard
Add support for zsh
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
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.
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}
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.
@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.
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!
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?