LoginSignup
1
2

More than 3 years have passed since last update.

Homebrewを使わずにMacへgit-completionとgit-prompを設定してみた

Posted at

背景

Macでgit-completionを使いたくなって設定方法を調べてみたが、Homebrewを使ってGitをインストールした前提での説明ばかりがヒットする。
私はひねくれ者だったらしく、GitのインストールにはHomebrewを使っていなかった。

Homebrewを使わずにGitをインストールした場合でも、git-completionを使えるようにする手順をまとめる。
ついでに、git-promptも設定した。

手順

1. 本体をダウンロード

# git-completion
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash

# git-prompt
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh -o ~/.git-prompt.sh

2. ~/.bashrcの編集

下記を追記する。
ファイルが存在しない場合は新規に作成する。

~/.bashrc
source $HOME/.git-completion.bash
source $HOME/.git-prompt.sh

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

3. ~/.bash_profileの編集

ターミナル起動時に~/.bashrcが読み込まれるように、下記を追記する。
ファイルが存在しない場合は新規に作成する。

~/.bash_profile
if [ -f ~/.bashrc ]; then
    . ~/.bashrc
fi

4. ターミナルを再起動

これで、gitの各種コマンドのタブ補完と、プロンプトにリポジトリの状態が表示されるようになる。

1
2
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
1
2