Mac下如何设置git completion

不得不说还说google大法好。不知道其他人有没有遇到过这个问题,就是在mac下想用git completion,意思就是在命令行敲git [tab]之后能显示git的智能提示指令,而不是显示当前文件夹下的文件,捣鼓了半天,终于搞定了。

首先我以为git-completion只有bash,而Mac下默认的zsh,所以是用不了这个脚本的,且我用brew下载git之后并没有像网上说的在/usr/local/etc下有一个文件夹名字为git/**/git-completion.d,我的是在/opt/homebrew/Cellar/git/2.31.1/etc/bash_completion.d,但问题是这个目录下面只有git-completion.bash,并不是我想要的.zsh文件,经过一番搜索,发现在/opt/homebrew/Cellar/git/2.31.1/share/zsh/site-functions下有一个文件_git,打开查看第一行写着# zsh completion wrapper for git,顿时茅塞顿开。

剩下的事情就变得异常的简单,只能说git做得实在是太好了,因为接下来我甚至都不用查什么资料,该文件开头注释清清楚楚告诉我要怎么做了

# 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',
# and then add the following to your ~/.zshrc file:
#
#  fpath=(~/.zsh $fpath)
#
# You need git's bash completion script installed. By default bash-completion's
# location will be used (e.g. pkg-config --variable=completionsdir bash-completion).
#
# If your bash completion script is somewhere else, you can specify the
# location in your ~/.zshrc:
#
#  zstyle ':completion:*:*:git:*' script ~/.git-completion.bash
#

不过我没按这个做法,稍微改了一下,将上述最后一行script ~/.git-completion.bash修改为script /opt/homebrew/Cellar/git/2.31.1/share/zsh/site-functions/_git,再手动source一下,就ok了。

参考文档:

https://oliverspryn.medium.com/adding-git-completion-to-zsh-60f3b0e7ffbc

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值