如何在 Mac 终端上显示完整路径和 git 分支 [英] How to display full path and git branch on Mac terminal

查看:79
本文介绍了如何在 Mac 终端上显示完整路径和 git 分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现某人的 mac 终端可以像这样显示完整路径和 git 分支:终端上的git分支和完整路径

I find someone's mac terminal can display both the full path and git branch like this : git branch and full path on terminal

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

I look at some materials and just can display the full path or git branch on the terminal seperatly. Could someone help me?

推荐答案

在终端中打开bash_profile:

nano ~/.bash_profile

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

and then add following in the bash_profile-file:

# 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/'
}

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

After that, restart the Terminal and then it works like follow:

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

这篇关于如何在 Mac 终端上显示完整路径和 git 分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆