美文网首页
Mac iterm2 配置git显示分支

Mac iterm2 配置git显示分支

作者: Eric_余浩 | 来源:发表于2018-12-06 18:02 被阅读77次

Mac iterm2 配置git显示分支

如下修改Mac的环境变量

  • 编辑环境变量配置文件
sudo vi /etc/profile
  • 复制以下代码在profile文件中
find_git_branch () {
    local dir=. head
    until [ "$dir" -ef / ]; do
        if [ -f "$dir/.git/HEAD" ]; then
            head=$(< "$dir/.git/HEAD")
            if [[ $head = ref:\ refs/heads/* ]]; then
                git_branch=" → ${head#*/*/}"
            elif [[ $head != '' ]]; then
                git_branch=" → (detached)"
            else
                git_branch=" → (unknow)"
            fi
            return
        fi
        dir="../$dir"
    done
    git_branch=''
}
PROMPT_COMMAND="find_git_branch; $PROMPT_COMMAND"
black=$'\[\e[1;30m\]'
red=$'\[\e[1;31m\]'
green=$'\[\e[1;32m\]'
yellow=$'\[\e[1;33m\]'
blue=$'\[\e[1;34m\]'
magenta=$'\[\e[1;35m\]'
cyan=$'\[\e[1;36m\]'
white=$'\[\e[1;37m\]'
normal=$'\[\e[m\]'

PS1="$white[$magenta\u$white@$green\h$white:$cyan\w$yellow\$git_branch$white]\$ $normal"

修改后的profile文件
  • wq保存profile文件,并执行source profile命令是刚才修改的配置文件使其生效。
  • 退出命令行,再次打开。就可以看到如下效果。
配置后可以显示当前分支

以上是基于bash这种终端的,其实在Mac系统上自带的终端有zsh,可以使用zsh实现git显示分支的效果

  • 查看系统安装的所有shell有哪些
cat /etc/shells
系统已经安装的shell

zsh这种shell是非常的强大的,同时其配置也异常的复杂,但是github上一个开源项目 oh-my-zsh 是的zsh的使用变得异常的简单

  • 通过wget自动安装oh-my-zsh
sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"

下载完成后重新启动iTerm即可愉快的使用zsh了,当然习惯使用bash的童鞋不要害怕,zsh是完全兼容bash的。

使用zsh显示git当前分支名称

相关文章

  • Mac iterm2 配置git显示分支

    Mac iterm2 配置git显示分支 如下修改Mac的环境变量 编辑环境变量配置文件 复制以下代码在profi...

  • Mac终端配置oh-my-zsh

    Mac终端配置oh-my-zsh Mac自带的终端在进入一个Git文件夹时不能显示当前所在的分支号,并且颜色上面也...

  • mac下终端iTerm2配置

    安装 iTerm2 && Oh My Zshmac下终端iTerm2配置# Mac OS 终端利器 iTerm2配置大全

  • git 常用命令

    1、git显示全部分支 git branch //显示本地分支git branch -a //显示远程分支 2、g...

  • git 分支

    git 显示所有分支(包含本地和远程)命令: git 删除本地分支命令: git 显示远程分支命令: git 删除...

  • git学习笔记

    配置信息 显示当前的Git配置 配置当前的用户信息 配置当前项目区分大小写 下载项目 分支 列出本地分支 列出远程...

  • mac 自己的bash_profile配置

    在Mac、Linux 终端显示 Git 当前所在分支:https://gist.github.com/yisibl...

  • Mac 终端显示git分支

    1 进入你的home目录cd ~ 2 编辑.bashrc文件vi .bashrc 3 将下面的代码加入到文件的最后...

  • Mac git分支颜色 显示

    Step 1 Step 2 Step 3

  • mac终端显示git分支

    本机环境10.15.7,终端默认shell是zsh1、切换到用户主目录cd ~,创建文件.git-prompt.s...

网友评论

      本文标题:Mac iterm2 配置git显示分支

      本文链接:https://www.haomeiwen.com/subject/bwzocqtx.html