Mac、Linux系統的終端顯示git當前分支

來源:互聯網
上載者:User

標籤:載入   設定檔   shell   檔案   ace   tty   rip   系統   sed   

1 進入你的home目錄

cd ~

 

2 編輯.bashrc檔案

vi .bashrc

 

3 將下面的代碼加入到檔案的最後處

function git_branch {  branch="`git branch 2>/dev/null | grep "^\*" | sed -e "s/^\*\ //"`"  if [ "${branch}" != "" ];then      if [ "${branch}" = "(no branch)" ];then          branch="(`git rev-parse --short HEAD`...)"      fi      echo " ($branch)"  fi}export PS1=‘\[email protected]\h \[\033[01;36m\]\W\[\033[01;32m\]$(git_branch)\[\033[00m\] \$ ‘
 

4 儲存退出

 
5 執行載入命令

source ./.bashrc
 

6 完成

Mac 下面啟動的 shell 是 login shell,所以載入的設定檔是.bash_profile,不會載入.bashrc。如果你是 Mac 使用者的話,需要再執行下面的命令,這樣每次開機後才會自動生效:

echo "[ -r ~/.bashrc ] && source ~/.bashrc" >> .bash_profile
 

Mac、Linux系統的終端顯示git當前分支

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.