chubin / cheat.sh

the only cheat sheet you need
https://cheat.sh/
MIT License
38.15k stars 1.78k forks source link

Zsh tab completion not working on Mac #266

Open ByronHsu opened 3 years ago

ByronHsu commented 3 years ago

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!

image

ab-10 commented 3 years ago

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
chubin commented 3 years ago

@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
LoLei commented 3 years ago

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
chubin commented 3 years ago

What version of zsh do you have?

$ zsh --version
zsh 5.4.2 (x86_64-ubuntu-linux-gnu)
LoLei commented 3 years ago

For me it's zsh 5.8.

dmitana commented 3 years ago

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
chubin commented 3 years ago

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)
dmitana commented 3 years ago

_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.

hsequeda commented 1 year ago

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.