Macのターミナルでgitのブランチを表示
毎回git branchコマンドで確認していたのでそろそろ導入する
Homebrewでgitをインストール
インストールされているか確認
$ brew list
なければインストール
$ brew install git
必要なファイルの取得
インストールが完了したら、以下ファイルをホームディレクトリに隠しファイルとしてコピー
git-completion.bash
$ cp /usr/local/Cellar/git/1.8.5.1/etc/bash_completion.d/git-completion.bash ~/.git-completion.bash
git-prompt.bash
$ cp /usr/local/Cellar/git/1.8.5.1/etc/bash_completion.d/git-prompt.sh ~/.git-prompt.sh
Githubからもインストール可
https://github.com/git/git/tree/master/contrib/completion
.bashrcにgitの設定を追記
bashのPS1にexportする
以下を.bashrcに追記
source ~/.git-completion.bash source ~/.git-prompt.sh GIT_PS1_SHOWDIRTYSTATE=true PS1='\[\033[32m\]\u@\h\[\033[00m\]:\[\033[34m\]\w\[\033[31m\]$(__git_ps1)\[\033[00m\]\$ ' export PS1=$PS1
表示はお好みに合わせて以下を参考に表示させる http://www.atmarkit.co.jp/flinux/rensai/linuxtips/002cngprmpt.html
再読み込み
$ source ~/.bashrc
ターミナルの環境設定で色を変更
デフォルトのままでは見にくいので
色 | RGB |
---|---|
レッド | (255, 100, 100) |
ブルー | (100, 100, 255) |
グリーン | (100, 255, 100) |
イエロー | (255, 255, 100) |
結果
いいかんじ