3
9

More than 5 years have passed since last update.

ターミナルで git の状態をわかりやすくする

Posted at

ただの自分用メモ。

どういう風になる?

git 管理外のディレクトリ等 (カレントディレクトリがルートの場合)
git_bash.png

git 管理下のディレクトリで更新(追加)ファイルが存在する場合
git_bash2.png

git 管理下のディレクトリで更新(追加)ファイルが存在し、 add 下ファイルがある場合
git_bash3.png

CentOS の場合

6.5, 6.8, 7.1 で確認。
vi ~/.bashrc でエディタを開き、任意の位置(自分は一番下で)に以下のテキストを貼り付けて保存し、 source ~/.bashrc を発行する。

git のバージョンやインストール方法によっては /usr/share/doc/git-1.7.1/contrib/completion/git-completion.bash のパスが変わるので、 find あたりで適当に検索する。

source /usr/share/doc/git-1.7.1/contrib/completion/git-completion.bash

GIT_PS1_SHOWDIRTYSTATE=true
PS1='[\[\033[40;1;32m\]\u\[\033[2;32m\]@\[\033[0m\]\[\033[40;32m\]\h \[\033[1;36m\]\W \[\033[31m\]$(__git_ps1 "(%s)")\[\033[0m\]\[\033[40;2;37m\]]\$ '
export PS1=$PS1

Mac OSX の場合

10.10, 10.11, 10.12 で確認。
vi ~/.bashrc でエディタを開き、任意の位置(自分は一番下で)に以下のテキストを貼り付けて保存し、 source ~/.bashrc を発行する。

git のバージョンやインストール方法によっては /usr/local/etc/bash_completion.d/git-prompt.sh/usr/local/etc/bash_completion.d/git-completion.bash のパスが変わるので、 find あたりで適当に検索する。

source /usr/local/etc/bash_completion.d/git-prompt.sh
source /usr/local/etc/bash_completion.d/git-completion.bash

GIT_PS1_SHOWDIRTYSTATE=true
PS1='[\[\033[40;1;32m\]\u\[\033[2;32m\]@\[\033[0m\]\[\033[40;32m\]\h \[\033[1;36m\]\W \[\033[31m\]$(__git_ps1 "(%s)")\[\033[0m\]\[\033[40;2;37m\]]\$\033[m '
export PS1=$PS1

細けぇこたぁいいんだよ

詳しく知りたければ bash の本とかを読んでください。
色の設定も詳しければ好みのものに変更できるので、おためしあれ。
なお、書いた人はそこまえ詳しくない上にデスマーチ中なので、疑問等にはお答えできますん。

3
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
9