git - 如何在 Mac 终端上显示完整路径和 git 分支
问题描述
我发现某人的 mac 终端可以像这样显示完整路径和 git 分支: git branch and full path on terminal
我看了一些资料,只能在终端上单独显示完整路径或 git 分支。有人可以帮助我吗?
解决方案
编辑:
bash_profile
在终端中打开:
nano ~/.bash_profile
然后在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/'
}
之后,重新启动终端,然后它的工作方式如下:
username: [~/path/to/current/directory] current-branch $
推荐阅读
- python - 如何实现在接收文件名时增加文件名的函数?
- javascript - 如何将数据发送到另一个页面?
- javascript - 猫鼬不验证更新的部分
- swift - 无法将“MobileNetV2”类型的值转换为预期的参数类型“VNCoreMLModel”
- json - 从 Pyomo 输出解析 JSON 变量数据
- node.js - 更改与其他文档相关的文档中的字段的方法
- c# - 无法统一引用游戏对象的 2D 数组
- html - 我是 html 的初学者,我的代码不起作用
- javascript - 兄弟组件不会在状态更改时重新渲染(使用 useEffect、useState 和 Context)
- swift - 当输入的值大于某个值时如何限制用户输入 Swift 5.1