ZSH TAB补全命令时候选项过多问题

问题描述

笔者最近重新装了zsh环境,使用Tab补全某些命令时,发现与之前操作习惯不太一样,导致非常的难受。
例如: 输入 git chec + tab补全命令,之前默认会补全为 git checkout 。但目前的情况如下:
在这里插入图片描述

定位问题

  1. 确认是否是插件影响,因为笔者刚装的环境 zsh 的 pluging 仅有 git 一个插件。看过其文件以后确认git 插件只是定义了一些 git 命令的别名。
    具体列表如下,命令还算全面。笔者本来打算,若解决不了这个问题就记别名使用了

Aliases

AliasCommand
ggit
gagit add
gaagit add --all
gapagit add --patch
gaugit add --update
gavgit add --verbose
gapgit apply
gaptgit apply --3way
gbgit branch
gbagit branch -a
gbdgit branch -d
gbdagit branch --no-color --merged | grep -vE “^([+]|\s( ( g i t m a i n b r a n c h ) ∣ (git_main_branch)| (gitmainbranch)(git_develop_branch))\s*$)” | xargs git branch -d 2>/dev/null
gbDgit branch -D
gblgit blame -b -w
gbnmgit branch --no-merged
gbrgit branch --remote
gbsgit bisect
gbsbgit bisect bad
gbsggit bisect good
gbsrgit bisect reset
gbssgit bisect start
gcgit commit -v
gc!git commit -v --amend
gcn!git commit -v --no-edit --amend
gcagit commit -v -a
gca!git commit -v -a --amend
gcan!git commit -v -a --no-edit --amend
gcans!git commit -v -a -s --no-edit --amend
gcamgit commit -a -m
gcasgit commit -a -s
gcasmgit commit -a -s -m
gcsmgit commit -s -m
gcbgit checkout -b
gcfgit config --list
gclgit clone --recurse-submodules
gccdgit clone --recurse-submodules “KaTeX parse error: Expected 'EOF', got '&' at position 4: @" &̲& cd "(basename $_ .git)”
gcleangit clean -id
gpristinegit reset --hard && git clean -dffx
gcmgit checkout $(git_main_branch)
gcdgit checkout $(git_develop_branch)
gcmsggit commit -m
gcogit checkout
gcorgit checkout --recurse-submodules
gcountgit shortlog -sn
gcpgit cherry-pick
gcpagit cherry-pick --abort
gcpcgit cherry-pick --continue
gcsgit commit -S
gdgit diff
gdcagit diff --cached
gdcwgit diff --cached --word-diff
gdctgit describe --tags $(git rev-list --tags --max-count=1)
gdsgit diff --staged
gdtgit diff-tree --no-commit-id --name-only -r
gdnolockgit diff $@ “:(exclude)package-lock.json” “:(exclude)*.lock”
gdupgit diff @{upstream}
gdvgit diff -w $@ | view -
gdwgit diff --word-diff
gfgit fetch
gfagit fetch --all --prune
gfggit ls-files | grep
gfogit fetch origin
gggit gui citool
ggagit gui citool --amend
ggfgit push --force origin $(current_branch)
ggflgit push --force-with-lease origin $(current_branch)
gglgit pull origin $(current_branch)
ggpgit push origin $(current_branch)
ggpnpggl && ggp
ggpullgit pull origin “$(git_current_branch)”
ggpurggu
ggpushgit push origin “$(git_current_branch)”
ggsupgit branch --set-upstream-to=origin/$(git_current_branch)
ggugit pull --rebase origin $(current_branch)
gpsupgit push --set-upstream origin $(git_current_branch)
ghhgit help
gignoregit update-index --assume-unchanged
gignoredgit ls-files -v | grep
git-svn-dcommit-pushgit svn dcommit && git push github $(git_main_branch):svntrunk
gkgitk --all --branches &!
gkegitk --all $(git log -g --pretty=%h) &!
glgit pull
glggit log --stat
glgpgit log --stat -p
glgggit log --graph
glggagit log --graph --decorate --all
glgmgit log --graph --max-count=10
glogit log --oneline --decorate
glolgit log --graph --pretty=‘%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset’
glolsgit log --graph --pretty=‘%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset’ --stat
glodgit log --graph --pretty=‘%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset’
glodsgit log --graph --pretty=‘%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ad) %C(bold blue)<%an>%Creset’ --date=short
glolagit log --graph --pretty=‘%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset’ --all
gloggit log --oneline --decorate --graph
glogagit log --oneline --decorate --graph --all
glpgit log --pretty=<format>
gmgit merge
gmomgit merge origin/$(git_main_branch)
gmtlgit mergetool --no-prompt
gmtlvimgit mergetool --no-prompt --tool=vimdiff
gmumgit merge upstream/$(git_main_branch)
gmagit merge --abort
gpgit push
gpdgit push --dry-run
gpfgit push --force-with-lease
gpf!git push --force
gpoatgit push origin --all && git push origin --tags
gprgit pull --rebase
gpugit push upstream
gpvgit push -v
grgit remote
gragit remote add
grbgit rebase
grbagit rebase --abort
grbcgit rebase --continue
grbdgit rebase $(git_develop_branch)
grbigit rebase -i
grbmgit rebase $(git_main_branch)
grbomgit rebase origin/$(git_main_branch)
grbogit rebase --onto
grbsgit rebase --skip
grevgit revert
grhgit reset
grhhgit reset --hard
grohgit reset origin/$(git_current_branch) --hard
grmgit rm
grmcgit rm --cached
grmvgit remote rename
grrmgit remote remove
grsgit restore
grsetgit remote set-url
grssgit restore --source
grstgit restore --staged
grtcd “$(git rev-parse --show-toplevel || echo .)”
grugit reset –
grupgit remote update
grvgit remote -v
gsbgit status -sb
gsdgit svn dcommit
gshgit show
gsigit submodule init
gspsgit show --pretty=short --show-signature
gsrgit svn rebase
gssgit status -s
gstgit status
gstagit stash push
gstagit stash save
gstaagit stash apply
gstcgit stash clear
gstdgit stash drop
gstlgit stash list
gstpgit stash pop
gstsgit stash show --text
gstugit stash --include-untracked
gstallgit stash --all
gsugit submodule update
gswgit switch
gswcgit switch -c
gswmgit switch $(git_main_branch)
gswdgit switch $(git_develop_branch)
gtsgit tag -s
gtvgit tag | sort -V
gtlgtl(){ git tag --sort=-v:refname -n -l ${1}* }; noglob gtl
gunignoregit update-index --no-assume-unchanged
gunwipgit log -n 1 | grep -q -c “--wip--” && git reset HEAD~1
gupgit pull --rebase
gupvgit pull --rebase -v
gupagit pull --rebase --autostash
gupavgit pull --rebase --autostash -v
glumgit pull upstream $(git_main_branch)
gwchgit whatchanged -p --abbrev-commit --pretty=medium
gwipgit add -A; git rm $(git ls-files --deleted) 2> /dev/null; git commit --no-verify --no-gpg-sign -m “–wip-- [skip ci]”
gamgit am
gamcgit am --continue
gamsgit am --skip
gamagit am --abort
gamscpgit am --show-current-patch
  1. git 版本 ,或者 zsh 版本问题,笔者找了几位同事对比版本号,发现可能是 zsh 版本造成的原因。
    在这里插入图片描述
    具体的区别在于x86_64-apple-darwin21.0 这点后缀,因为笔者没搜到相关信息,没办法针对这个猜想进行验证。

解决方案

功夫不负有心人,笔者在搜索相关资料时看到了这篇文章:

hiding certain options in zsh autocompletion

具体步骤:

  1. vim ~/.zshrc

笔者这里屏蔽了check-* 相关命令 和 cheery 的两个命令
编辑 zsh 配置文件 ,追加以下代码:

zstyle ':completion::complete:git:*:*' ignored-patterns 'check*-*' 'cherry' 'cherry-pick'
  1. 重新载入配置文件
source ~/.zshrc

或者

zsh
  1. 开启一个新终端验证
    在这里插入图片描述

结语

当前的配置已经满足笔者的需求,如果各位小伙伴想深究原理可以看一下下面这篇文档。
Standard Styles

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值