你真的应该使用git_156;pluging_157;命令来提取你想要的信息。__瓷_命令的输出(例如
git status
)可能会随时间变化,但__pitting_命令的行为更稳定。
有了瓷质界面,也可以不用__bashisms_157;或_156;zshisms_157;(即
=~
匹配运算符):
parse_git_branch() {
in_wd="$(git rev-parse --is-inside-work-tree 2>/dev/null)" || return
test "$in_wd" = true || return
state=''
git update-index --refresh -q >/dev/null # avoid false positives with diff-index
if git rev-parse --verify HEAD >/dev/null 2>&1; then
git diff-index HEAD --quiet 2>/dev/null || state='*'
else
state='#'
fi
(
d="$(git rev-parse --show-cdup)" &&
cd "$d" &&
test -z "$(git ls-files --others --exclude-standard .)"
) >/dev/null 2>&1 || state="${state}+"
branch="$(git symbolic-ref HEAD 2>/dev/null)"
test -z "$branch" && branch='<detached-HEAD>'
echo "${branch#refs/heads/}${state}"
}
将输出集成到提示符中仍然是shell特有的(即,转义或引用
$
(两者兼而有之)
猛击
和
ZSH
)并设置提示
ZSH
)