cheat.sh
cheat.sh copied to clipboard
Zsh tab completion not working on Mac
Hi, I've installed tab completion script following the commands.
$ curl https://cheat.sh/:zsh > ~/.zsh.d/_cht
$ echo 'fpath=(~/.zsh.d/ $fpath)' >> ~/.zshrc
$ # Open a new shell to load the plugin
However, even if I have ran source ~/.zshrc, when I type cht.sh go/f, the suggestion didn't show up.
Am I missing something? Thanks!

I've tried to replicate your error on my MacOS Catalina 10.15, but was unable to do so. Following the steps you outlined leads to working zsh completion on both the default terminal and iTerm 2.
When you execute _cht what do you get?
You're supposed to get:
_arguments:comparguments:325: can only be called from completion function
@ab-10 Armin, thank you for helping with this. I can't reproduce it either
@ByronHsu Is it possible that you don't do compinit in your ~/.zshrc?
I tired to reproduce it, but it works for me too:
$ tail -4 ~/.zshrc
fpath=(~/.zsh.d/ $fpath)
autoload -U compinit
compinit
$ zsh
% cht.sh go/<TAB>
Cheat Sheets
go/ go/Declarations go/func go/if go/Maps go/print go/Structs
go/Arrays go/Embedding go/go go/Interfaces go/Operators go/range go/switch
go/Axioms go/Errors go/hello go/:learn go/packages go/rosetta/ go/types
go/Channels go/for go/http go/:list go/Pointers go/slices
It doesn't work for me on Linux either, with the same described behavior.
When I execute it I get the following:
$ zsh _cht
_cht:4: command not found: _arguments
$ ./_cht # after chmod +x (this probably isn't intended)
./_cht: 3: Syntax error: "(" unexpected
What version of zsh do you have?
$ zsh --version
zsh 5.4.2 (x86_64-ubuntu-linux-gnu)
For me it's zsh 5.8.
I also have zsh 5.8 and had the same problem.
$ zsh --version
zsh 5.8 (x86_64-pc-linux-gnu)
Adding compinit to my .zshrc solved the issue, and tab completion works now.
However, executing _cht still results in the following:
$ zsh _cht
_cht:4: command not found: _arguments
But you are not supposed to execute _cht, you just use it.
I've tested it tab-completion with zsh 5.8, and everything perfectly works.
$ cht.sh go/<TAB>
Cheat Sheets
go/ go/Channels go/Maps go/func go/packages go/switch
go/:learn go/Declarations go/Operators go/go go/print go/types
go/:list go/Embedding go/Pointers go/hello go/range
go/Arrays go/Errors go/Structs go/http go/rosetta/
go/Axioms go/Interfaces go/for go/if go/slices
$ zsh --version
zsh 5.8 (x86_64-ubuntu-linux-gnu)
_cht execution was only a reaction to @ab-10's comment.
Yes, after adding compinit tab-completion works flawlessly. I wanted only to confirm your suggestion because there were no reactions from others on whether compinit solved the issue.
Maybe not everyone is aware of compinit, and adding a note that compinit is required to the ZSH Tab completion section in README would be suitable.
I solved the problem adding this to my .zshrc file =>
fpath=(~/.zsh.d/ $fpath)
autoload -Uz +X compinit bashcompinit
compinit
bashcompinit
Ensure of call the compinit after the fpath declaration, if not the compinit command will not load the addition of ~/.zsh.d path to the fpath.