【问题标题】:How to display full path and git branch on Mac terminal如何在 Mac 终端上显示完整路径和 git 分支
【发布时间】:2021-02-28 21:00:02
【问题描述】:

我发现某人的 mac 终端可以像这样显示完整路径和 git 分支: git branch and full path on terminal

我看了一些资料,只能在终端上单独显示完整路径或 git 分支。有人可以帮我吗?

【问题讨论】:

    标签: git macos terminal


    【解决方案1】:

    编辑:

    在终端打开bash_profile

    nano ~/.bash_profile
    

    然后在bash_profile-文件中添加以下内容:

    # to see always fullpath and current git-branch
    export PS1="\[\033[36m\]\u\[\033[m\]: \[\033[34m\][\w]\[\033[m\]\[\033[32m\]\$([[ -n \$(git branch 2> /dev/null) ]] && echo)\$(parse_git_branch)\[\033[m\] \$ "
    
    # find out current branch
    parse_git_branch() {
            git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \1/'
    }
    

    之后,重新启动终端,然后它的工作方式如下:

    username: [~/path/to/current/directory] current-branch $ 
    

    【讨论】:

    • 感谢您的帮助,但它只显示完整路径,不包括 git 分支
    • 我已经编辑了答案,现在我希望它符合您的要求!
    • 你看到我的回答了吗?
    • 是的!这很有帮助!再次感谢!我的 shell 一直使用 oh-my-zsh,它更容易设置。
    猜你喜欢
    • 2012-09-28
    • 2013-06-24
    • 2011-12-15
    • 2021-12-05
    • 1970-01-01
    • 2023-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多