Skip to content
This repository was archived by the owner on Jul 11, 2022. It is now read-only.
This repository was archived by the owner on Jul 11, 2022. It is now read-only.

Zsh command completion does not work #295

@mattstein

Description

@mattstein

Description

Nitro’s command completion for Zsh on macOS does not work as described in the docs and craftcms/docs#170.

It looks like this is because the zsh command script output is for a command called zsh when it should be for a command called nitro. So whether you follow the instructions to write a ~/.zsh/completions/_nitro file or source <(nitro completion zsh) in your profile—two ways of doing the same thing once zsh completions are enabled—command completion fails to work.

Workaround

I’ve successfully tested a workaround on two machines by editing the static ~/.zsh/completions/_nitro output as written by Nitro 2.0.4 and 2.0.5:

  1. Make sure the following exist somewhere in ~/.zshrc, to set a completion path and enable built-in Zsh completions:
    fpath=(~/.zsh/completion $fpath)
    autoload -Uz compinit && compinit -i
    
  2. Run nitro completion zsh > "${fpath[1]}/_nitro" to write Nitro’s Zsh completion script to ~/.zsh/completion/_nitro.
  3. Edit ~/.zsh/completion/_nitro to fix two lines and define a nitro function rather than zsh:
    • First line should read #compdef _nitro nitro.
    • Line 13 should read _nitro() instead of _zsh().
  4. Start a new shell session and type nitro + tab to see Nitro’s command completion working:
    Screen Shot 2021-03-15 at 11 58 14 AM

It looks like the culprit could be here: https://github.com/craftcms/nitro/blob/main/command/completion/zsh.go#L12

And I’m probably wrong because I’m lost with Go, but Cobra is definitely looking for %[1]s and wanting to write nitro in its place: https://github.com/spf13/cobra/blob/master/zsh_completions.go#L78

Steps to reproduce

  1. Follow the instructions for Zsh in the docs.
  2. Observe that Nitro command completion does not work.
  3. You can optionally wreck your environment or source <(nitro completion zsh) from ~/.zshrc, but nothing will work—presumably because of the situation I described above where the wrong function is being defined.

Additional info

  • Nitro version: 2.0.4 and 2.0.5
  • Shell: zsh 5.8 (x86_64-apple-darwin20.0), with oh-my-zsh
  • Docker version: n/a

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions