Skip to content

Instantly share code, notes, and snippets.

@juno
Created May 9, 2013 08:09
Show Gist options
  • Star 26 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juno/5546179 to your computer and use it in GitHub Desktop.
Save juno/5546179 to your computer and use it in GitHub Desktop.
zshでgitの補完を設定する手順。

gitのソースツリーに含まれるgit-completion.zshをzshで使う手順

注意:gitコマンドがhubコマンドへのエイリアスに設定されている場合は補完が働かない。

補完用ファイルを置くディレクトリを作成する(既に同じ用途のディレクトリがある場合はそれを使う)。

$ mkdir ~/.zsh/completion/

git-completion.bashgit-completion.zshをダウンロードする。この2つは同じディレクトリに置く必要がある。

$ cd ~/.zsh/completion/
$ curl -O https://raw.github.com/git/git/master/contrib/completion/git-completion.bash
$ curl -O https://raw.github.com/git/git/master/contrib/completion/git-completion.zsh

git-completion.zsh_gitにリネームする。

$ mv git-completion.zsh ~/.zsh/completion/_git
$ ls -l
total 136
-rw-r--r--  1 juno  staff   5384  5  9 16:58 _git
-rw-r--r--  1 juno  staff  56170  5  9 16:55 git-completion.bash

.zshrcに以下のような設定を追加する。既に記述済みの設定がある場合は適宜調整する。

fpath=(~/.zsh/completion $fpath)

autoload -U compinit
compinit -u

fpathの設定がcompinitよりも後にあると動作しないので注意。

zcompdumpをリビルドする。

$ rm -f ~/.zcompdump; compinit

シェルを再起動すれば、gitでサブコマンドやブランチ名の補完が有効になる。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment