LoginSignup
4

More than 1 year has passed since last update.

Git の補完が brew 版と MacOS 版で違う

Last updated at Posted at 2022-05-18

つまり……

MacOS の標準の Git の補完を使うことにした
→ と思ったけどやっぱり新しい方を使うことにした

やったこと

$ cp /usr/local/Cellar/git/2.36.0/share/zsh/site-functions/* ~/.zfunctions/Completion/.

なにかが足りない

$ git push -[TAB]

で補完できなかったりしたので,気になって見てみた

$ echo $fpath
/usr/local/share/zsh/site-functions /usr/share/zsh/site-functions /usr/share/zsh/5.8/functions

brew を先に見てるようだった

$ ls -l /usr/local/share/zsh/site-functions/_git
/usr/local/share/zsh/site-functions/_git -> ../../../Cellar/git/2.36.0/share/zsh/site-functions/_git
$ ls /usr/share/zsh/5.8/functions/_git
/usr/share/zsh/5.8/functions/_git

中身結構違う

$ head /usr/local/share/zsh/site-functions/_git.a
#compdef git gitk

# zsh completion wrapper for git
#
# Copyright (c) 2012-2020 Felipe Contreras <felipe.contreras@gmail.com>
#
# The recommended way to install this script is to make a copy of it as a
# file named '_git' inside any directory in your fpath.
#
# For example, create a directory '~/.zsh/', copy this file to '~/.zsh/_git',
$ head /usr/share/zsh/5.8/functions/_git
#compdef git git-cvsserver git-receive-pack git-upload-archive git-upload-pack git-shell gitk tig

# Some parts of this completion's behaviour are configurable:
#
# Say you got your own git sub-commands (git will run a program `git-foo'
# when you run "git foo") and you want "git f<tab>" to complete that sub
# commands name for you. You can make that sub-command known to the completion
# via the user-command style:
#
#     % zstyle ':completion:*:*:git:*' user-commands foo:'description for foo'

試しに,brew 版を使わないようにしたら上記補完できたのでこちらにすると良さそう.

$ mv /usr/local/share/zsh/site-functions/_git /usr/local/share/zsh/site-functions/_git.a

$ git push -
not a git repository
option
--all                          -- push all refs under refs/heads/
--atomic                       -- request atomic transaction on remote side
--delete               -d      -- delete all listed refs from the remote repository
(snip)

そもそも

$ where git
/usr/local/bin/git
/usr/bin/git
$ /usr/local/bin/git --version
git version 2.36.0
$ /usr/bin/git --version
git version 2.32.0 (Apple Git-132)

あまり変わらなそうなので,こだわらなければ brew 版をアンインストールしてもいいかも.

Refs

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
4