原因macOS的默认终端从bash变成了zsh 。
1,修改 ~/.zshrc,
如果没有该文件,可以直接创建
vim ~/.zshrc 使用该命令,如果没有该文件的话,会自动创建,如果有的话,会进入该文件的编辑态
在该文件最后加一句 source /etc/profile
2,修改/etc/profile
鼠标放在桌面上,最上面的菜单有前往,下拉框有前往指定文件夹,输入/etc/就好,找到profile,把peofile的文件复制出来,将
- function parse_git_branch() {
- git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/[\1]/p'
- }
-
- setopt PROMPT_SUBST
- export PROMPT='%F{grey}%n%f %F{cyan}%~%f %F{green}$(parse_git_branch)%f %F{normal}$%f '
粘贴到最后
这是我的profile的所有配置
- # System-wide .profile for sh(1)
-
- if [ -x /usr/libexec/path_helper ]; then
- eval `/usr/libexec/path_helper -s`
- fi
-
- if [ "${BASH-no}" != "no" ]; then
- [ -r /etc/bashrc ] && . /etc/bashrc
- fi
-
- function parse_git_branch() {
- git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/[\1]/p'
- }
- setopt PROMPT_SUBST
- export PROMPT='%F{grey}%n%f %F{cyan}%~%f %F{green}$(parse_git_branch)%f %F{normal}$%f '
将文件保存为profile,然后替换/etc 下的profile
3;保存文件,使之生效果
source ~/.zshrc
然后git分支就出现了