I use this function in bash
function parse_git_branch { git_status="$(git status 2> /dev/null)" pattern="^# On branch ([^${IFS}]*)" if [[ ! ${git_status}} =~ "working directory clean" ]]; then state="*" fi
but I decided to use zsh. Although I can use this as a shell script (even without shebang) in my .zshrc, the error is a parse error on this line if [[ ! ${git_status}} if [[ ! ${git_status}} ...
What do I need to do to prepare it for zshell?
Edit: The "actual error" I get is " parse error near } , and it refers to a weird double }} that runs on Bash.
Edit: Here is the last code, just for fun:
parse_git_branch() { git_status="$(git status 2> /dev/null)" pattern="^# On branch ([^[:space:]]*)" if [[ ! ${git_status} =~ "working directory clean" ]]; then state="*" fi if [[ ${git_status} =~ ${pattern} ]]; then branch=${match[1]} echo "(${branch}${state})" fi } setopt PROMPT_SUBST PROMPT='$PR_GREEN%n@$PR_GREEN%m%u$PR_NO_COLOR:$PR_BLUE%2c$PR_NO_COLOR%(!.#.$)' RPROMPT='$PR_GREEN$(parse_git_branch)$PR_NO_COLOR'
Thank you all for your patience and help.
Edit: The best answer taught us all: git status is china (UI). Good scenarios go against GIT plumbing. Here's the final function:
# The latest version of Chris' function below PROMPT='$PR_GREEN%n@$PR_GREEN%m%u$PR_NO_COLOR:$PR_BLUE%2c$PR_NO_COLOR%(!.
Please note that only the invitation is zsh specific. In Bash, this will be your invitation plus "\$(parse_git_branch)" .
It may be slower (more GIT calls, but this is an empirical question), but it will not be violated by changes in GIT (they do not change the plumbing). And this is very important for a good forward script.
git bash zsh
Dan rosenstark
source share