ubuntu使用git時,終端不顯示git分支。

1:問題描述:html

  在Windows環境下習慣使用git bash操做git分支,最近學習linux環境,發現linux環境終端不顯示git分支,相關現象以下:
linux

       

  指望效果是:webpack

    

  個人linux環境版本是:Ubuntu 18.04 LTSgit

       系統默認的終端是:Terminalgithub

2:修改方案:web

   經過百度,找到解決方案:oh-my-zshshell

  1:oh-my-zsh介紹:json

        oh-my-zsh是基於Zsh(Zsh是一個Linux用戶不多使用的power-shell,這是因爲大多數Linux產品安裝,以及默認使用bash shell)的功能做了一個擴展,方便插件管理、主體自定義等。ubuntu

        oh-my-zsh源碼在  https://github.com/robbyrussell/oh-my-zsh ,它的License爲MIT。vim

  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查看分支的時候,發現會打開新的界面顯示結果,使用很不方便。

相關文章
相關標籤/搜索