码迷,mamicode.com
首页 > 其他好文 > 详细

解决oh-my-zsh中git分支显示乱码问题

时间:2019-08-11 23:11:39      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:格式   png   and   div   文件夹   git   status   代码   info   

oh-my-zsh显示github分支时,如果当前文件夹不是git仓库,它就会显示乱码。倒腾了好几个小时终于弄清楚是oh-my-zsh中函数”git_prompt_info“的锅,然后又花了半个多小时调代码,现在总算像个人了!!

先看效果:

技术图片

实现步骤:

  1. 进入 ~/.oh-my-zsh/lib 文件夹
  2. 编辑 git.zsh,找到git_prompt_info函数:

    技术图片

    function git_prompt_info() {
      local ref
      if [[ "$(command git config --get oh-my-zsh.hide-status 2>/dev/null)" != "1" ]]; then
        ref=$(command git symbolic-ref HEAD 2> /dev/null) ||     if [[ -n $ref ]]; then
          ref=$(command git rev-parse --short HEAD 2> /dev/null) || return 0
        fi
        if [[ -n ${ref#refs/heads/} ]]; then
          echo " ${ref#refs/heads/}"
        fi
      fi
    }

    这里修改显示逻辑,如果当前文件夹属于git仓库,就显示分支,否则什么也不显示。

  3. 进入 ~/.oh-my-zsh/thems 文件夹,编辑robbyrussell.zsh-theme

    技术图片

    local ret_status="%(?:%{$fg_bold[green]%}?:%{$fg_bold[red]%}?)"
    PROMPT=‘${ret_status} %{$fg[cyan]%}%c%{$fg_bold[blue]%}$(git_prompt_info) %{$reset_color%}$ ‘
    ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}"
    ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} "
    ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}?"
    ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})"
    

    这里是修改prompt格式,直接拷贝进去就好,不要漏空格,否则会很丑。

 大功告成~! 

 

解决oh-my-zsh中git分支显示乱码问题

标签:格式   png   and   div   文件夹   git   status   代码   info   

原文地址:https://www.cnblogs.com/Rhythm-/p/11337006.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!