ubuntu使用git时,终端不显示git分支。

1:问题描述:

  在Windows环境下习惯使用git bash操作git分支,最近学习linux环境,发现linux环境终端不显示git分支,相关现象如下:

       

  期望效果是:

    

  我的linux环境版本是:Ubuntu 18.04 LTS

       系统默认的终端是:Terminal

2:修改方案:

   通过百度,找到解决方案:oh-my-zsh

  1:oh-my-zsh介绍:

        oh-my-zsh是基于Zsh(Zsh是一个Linux用户很少使用的power-shell,这是由于大多数Linux产品安装,以及默认使用bash shell)的功能作了一个扩展,方便插件管理、主体自定义等。

        oh-my-zsh源码在  https://github.com/robbyrussell/oh-my-zsh ,它的License为MIT。

  2:oh-my-zsh安装:

安装zsh:
hlp@hlp:~/code/github_code/git_mytest$ sudo apt install zsh
查看安装成功:
hlp@hlp:~/code/github_code/git_mytest$ zsh --version
zsh 5.4.2 (x86_64-ubuntu-linux-gnu)
安装
oh-my-zsh:
hlp@hlp:~/code/github_code/git_mytest$ sh -c "$(wget https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh -O -)"

 

   附图:安装成功的标志:

  

  3:结果验证:  

启动zsh终端:
hlp@hlp:~/code/github_code/git_mytest$ zsh ➜ git_mytest git:(master) ls ------》成功显示了分支 doc LICENSE README.md src webpack.config.js example package.json release SUMMARY.md ➜ git_mytest git:(master) exit -----》退出zsh终端 hlp@hlp:~/code/github_code/git_mytest$

      4:配置修改:

分支显示颜色修改:
进入配置文件:

hlp@hlp:~/code/github_code/git_mytest$ vi ~/.oh-my-zsh/themes/robbyrussell.zsh-theme 修改后的配置文件:
hlp@hlp:
~/code/github_code/git_mytest$ cat ~/.oh-my-zsh/themes/robbyrussell.zsh-theme local ret_status="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ )" PROMPT='${ret_status} %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)' ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[blue]%}git:(%{$fg[green]%}" ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} " ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}✗" ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})" 配置文件生效查看:
hlp@hlp:
~/code/github_code/git_mytest$ zsh
➜  git_mytest git:(master) ls   

zsh主题修改:

查看自带默认主题:
hlp@hlp:~/code/github_code/git_mytest$ ls ~/.oh-my-zsh/themes -----》这里没有输出显示结果

修改主题:
hlp@hlp:~/code/github_code/git_mytest$ vi ~/.zshrc
hlp@hlp:~/code/github_code/git_mytest$ cat ~/.zshrc
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation.
  export ZSH="/home/hlp/.oh-my-zsh"

# Set name of the theme to load. Optionally, if you set this to "random"
# it'll load a random theme each time that oh-my-zsh is loaded.
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="robbyrussell" ------》修改该字段即可修改主题,相关主题可以参考:https://github.com/robbyrussell/oh-my-zsh/wiki/Themes

# Set list of themes to load
# Setting this variable when ZSH_THEME=random
# cause zsh load theme from this variable instead of

zsh插件修改:(zsh默认只有git插件)
查看系统默认插件:
hlp@hlp:~/.oh-my-zsh/plugins$ ls ~/.oh-my-zsh/plugins

修改插件配置文件:
hlp@hlp:~/code/github_code/git_mytest$ vi ~/.zshrc
hlp@hlp:~/code/github_code/git_mytest$ cat ~/.zshrc
。。。。。。
# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(
  git wd web-search history history-substring-search ------》增加想要的插件,插件介绍:https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins
)
。。。。。

除此之外,~/.zshrc文件中其他注释掉的配置信息,可以参考相关文档自行修改达到自己想要的效果。
例如给history增加时间:
  1. $ vim ~/.zshrc
  2. HIST_STAMPS="yyyy-mm-dd"
  3. source ~/.zshrc
卸载:
直接在终端中,运行uninstall_oh_my_zsh既可以卸载。

 

3:参考文献:(有照抄的嫌疑,太详细了)

 主要参考:http://www.mamicode.com/info-detail-2163847.html

        https://blog.csdn.net/czg13548930186/article/details/72858289

4:声明:

  该博文只是为了规范自己的习惯,总结遇到过的问题,如有问题或者建议,请谅解。

 

 

 

5:遗留小问题(待处理):

  进入zsh终端后,我用git branch查看分支的时候,发现会打开新的界面显示结果,使用很不方便。

posted @ 2018-07-22 01:24  梦归处/码农变形记  阅读(4243)  评论(0编辑  收藏  举报