Skip to content

Instantly share code, notes, and snippets.

@d-kuro
Last active April 20, 2023 01:25
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d-kuro/352498c993c51831b25963be62074afa to your computer and use it in GitHub Desktop.
Save d-kuro/352498c993c51831b25963be62074afa to your computer and use it in GitHub Desktop.
zsh で git コマンドの補完を有効にする

zsh で git コマンドの補完を有効にする

brew で git をインストールした

$ ls -l `brew --prefix`/share/zsh/site-functions/

_gitgit-completion.bash が表示されていることを確認する。

だめだったら以下

$ brew link git
$ brew link --overwrite git

zcompdump のリビルド

$ rm -f ~/.zcompdump; compinit

brew じゃない

$ mkdir ~/.zsh/completion/
$ 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
$ mv git-completion.zsh _git

.zshrc

# brew  の場合
fpath=($(brew --prefix)/share/zsh/site-functions $fpath)

# brew じゃない
fpath=(~/.zsh/completion $fpath)

# 補完機能有効にする
autoload -U compinit
compinit -u
 
# 補完候補に色つける
autoload -U colors
colors
zstyle ':completion:*' list-colors "${LS_COLORS}"
 
# 単語の入力途中でもTab補完を有効化
setopt complete_in_word
# 補完候補をハイライト
zstyle ':completion:*:default' menu select=1
# キャッシュの利用による補完の高速化
zstyle ':completion::complete:*' use-cache true
# 大文字、小文字を区別せず補完する
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Z}'
# 補完リストの表示間隔を狭くする
setopt list_packed
 
# コマンドの打ち間違いを指摘してくれる
setopt correct
SPROMPT="correct: $RED%R$DEFAULT -> $GREEN%r$DEFAULT ? [Yes/No/Abort/Edit] => "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment