社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

Chris Johnsen

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

你真的应该使用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 )