私信  •  关注

Dennis Williamson

Dennis Williamson 最近创建的主题
Dennis Williamson 最近回复了
13 年前
回复了 Dennis Williamson 创建的主题 » 从bash将parse git_分支函数转换为zsh(提示)

你可以使用数组 match 而不是 $BASH_REMATCH . 你也可以避开额外的闭合花括号。

未经测试的:

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=${match[1]}
    echo "(${branch}${state})"
  fi
}

试一试,看看是否有帮助。