简体   繁体   English

如何在 Mac 终端上显示完整路径和 git 分支

[英]How to display full path and git branch on Mac terminal

I find someone's mac terminal can display both the full path and git branch like this : git branch and full path on terminal我发现某人的 mac 终端可以像这样显示完整路径和 git 分支:终端上的 git branch 和完整路径

I look at some materials and just can display the full path or git branch on the terminal seperatly.我查看了一些材料,只能在终端上单独显示完整路径或git分支。 Could someone help me?有人可以帮助我吗?

EDIT:编辑:

Open bash_profile in the terminal:在终端中打开bash_profile

nano ~/.bash_profile

and then add following in the bash_profile -file:然后在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 $ 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM