Skip to content

Generate autocomplete script to /dev/stdout #2511

@GeertJohan

Description

@GeertJohan

I'm using restic 0.9.6 compiled with go1.13.4 on linux/amd64

I'm trying to add autocomplete to my .zshrc by adding this line:

source <(restic generate --zsh-completion /dev/stdout)

Having generated completion in zshrc is very common in the k8s ecosystem;

source <(kubectl completion zsh)
source <(minikube completion zsh)
source <(helm completion zsh)

This is quite cool because the user doesn't have to think about overwriting a previously generated completion script when they upgrade the tool.

However, it doens't work with restic, because restic writes a message to /dev/stdout when running the generate command.

writing zsh completion file to /dev/stdout

This message breaks interpreting the outputted script. When I start a new terminal with zsh in it:

/proc/self/fd/13:1: command not found: writing
_arguments:comparguments:325: can only be called from completion function
_arguments:comparguments:325: can only be called from completion function

The first line, "command not found: writing" seems to relate to the "writing zsh completion file to /dev/stdout" message.

I would like to have a way to achieve the same as kubectl and other tools, generating the latest autocomplete code when starting a new terminal with zsh so that the autocomplete is always up-to-date.

Maybe the message can be written to /dev/stderr so that it can be filtered in .zshrc, or the message is silenced when using /dev/stdout as output file?

I didn't report this as a bug because generating the autocomplete code to /dev/stdout probably isn't what the author of the autocomplete functionality had in mind.

If the maintainer of this software agrees with a proposed solution, I'd be very happy to work on a PR.

Did restic help you today? Did it make you happy in any way?

It's huge. Having an easy tool to maintain secure offsite backups is great. Since restic, I backup more often. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions