LoginSignup
24
25

More than 5 years have passed since last update.

Macのターミナル(bash)でGitを使いやすくしてみた。(補完、branch表示)

Last updated at Posted at 2015-07-15

やったこと

最初は oh-my-zsh を使用したやり方を検討したが bash を使い続ける方向でやり方を探した。
(複数の環境でターミナルを操作するのでいちいち環境を揃えるのが面倒なため)

  • gitで補完ができるようにした。(特にbranch名とか)
  • 現在のbranch名を表示するようにした。

補完機能

まずは必要ファイルがあるかどうか確認。

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

最新のMacのデフォルトのgitでは入ってない可能性があるので、ない場合はbrewコマンドなどでgitをインストールしなおす。

$ brew install git

.bash_profile, .bashrc のどちらかに以下の記述を追加する。

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

現在のbranch名の表示

.bash_profile, .bashrc のどちらかに以下の記述を追加する。

.bash_profile
GIT_PS1_SHOWDIRTYSTATE=true
export PS1='\h\[\033[00m\]:\W\[\033[31m\]$(__git_ps1 [%s])\[\033[00m\]\$ '

設定の反映

終わったら設定を反映させる。

$ source ~/.bash_profile
24
25
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
24
25