1. 程式人生 > >ubuntu使用git時,終端不顯示git分支。

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

rand alt arch ons set window when png order

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

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