Translate This git_parse_function to zsh?

Posted by yar on Stack Overflow See other posts from Stack Overflow or by yar
Published on 2010-05-17T15:32:55Z Indexed on 2010/05/17 16:00 UTC
Read the original article Hit count: 197

Filed under:
|

I am using 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
  # add an else if or two here if you want to get more specific

  if [[ ${git_status} =~ ${pattern} ]]; then
    branch=${BASH_REMATCH[1]}
    echo "(${branch}${state})"
  fi
}

but I'm determined to use zsh. While I can use this perfectly as a shell script (even without a shebang) in my .zshrc the error is a parse error on this line if [[ ! ${git_status}}...

What do I need to do to get it ready for zshell?

Note: I realize the answer could be "go learn zsh syntax," but I was hoping for a quick hand with this if it's not too difficult.

© Stack Overflow or respective owner

Related posts about zsh

Related posts about git