zoukankan      html  css  js  c++  java
  • 解决oh-my-zsh中git分支显示乱码问题

    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格式,直接拷贝进去就好,不要漏空格,否则会很丑。

     大功告成~! 

  • 相关阅读:
    NGINX 代理以及 HTTPS (一)
    HTTP 各种特性应用(二)
    HTTP 各种特性应用(一)
    HTTP 协议基础及发展历史
    添加 表格
    C# 利用反射和特性 来做一些事情
    HTTP 与 HTTPS
    系统登录详解
    js表单提交到后台对象接收
    idea插件
  • 原文地址:https://www.cnblogs.com/Rhythm-/p/11337006.html
Copyright © 2011-2022 走看看