Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Completions for restic not loading #8177

Closed
karthink opened this issue Jul 27, 2021 · 5 comments
Closed

Completions for restic not loading #8177

karthink opened this issue Jul 27, 2021 · 5 comments
Labels

Comments

@karthink
Copy link

  • Fish: version 3.3.1
  • OS: Arch Linux, kernel 5.11.16-arch1-1
  • Terminal: st
  • Tested without third-party customizations: Yes.

The CLI backup program restic can generate a fish-completions file, as described here. The generated file is here.

I saved this file as ~/.config/fish/completions/restic.fish and also ran source restic.fish, which did not report any errors.

However I'm not getting any completions, either of subcommands (restic mount, restic backup etc), or of command line options. Am I missing any steps?

@faho faho added the question label Jul 28, 2021
@faho
Copy link
Member

faho commented Jul 28, 2021

This is a quite awkward completion script, and does a few very unorthodox and very much not recommended things.

For instance:

  • It erases pre-existing completions - this isn't recommended because it simply doesn't happen
  • It triggers its own completions - I don't even know what this is supposed to fix
  • It tries to trigger file completions when nothing else is available - which we've disabled on purpose because it's an awful way of working
  • It tries to cache the completions by running the script in the condition and putting the output in a variable
  • It uses eval

Basically it's a very direct translation of the bash/zsh completions, made for parity, instead of working with fish's system.

There's a bunch of debugging stuff in there if you set $BASH_COMP_DEBUG_FILE (yes, that's "BASH").

So: set -g BASH_COMP_DEBUG_FILE /tmp/restic-debug and run the completions.

But you probably want to talk to upstream, as I don't have restic.

@faho
Copy link
Member

faho commented Jul 28, 2021

E.g. this part:

# Since Fish completions are only loaded once the user triggers them, we trigger them ourselves
# so we can properly delete any completions provided by another script.

Is entirely wrong in every way. One, you don't want to erase the completions, two: they are already being loaded. That's how you get into this file.

@faho
Copy link
Member

faho commented Jul 28, 2021

Okay, the fish completion generation was enabled in restic/restic@9cc1ecd, committed after the last release, so I don't believe it's available in a release yet.

I tested with your file and restic 0.12.0, and it does indeed try to execute restic __complete SOMETHING, and it fails with

unknown command "__complete" for "restic"

So... unless you're testing restic from git, it's simply not available yet.

Other than that, the completions are generated by https://github.com/spf13/cobra, so if you have problems with these, you should ask there.

@karthink
Copy link
Author

Thank you for looking into it. I'm a restic end user and not familiar with the internal workings of either fish or restic, so I can't fix the completion script. I got the completion script from the restic forums since my distro's version of restic didn't have the generation feature for fish (as you point out).

I'll wait for the Arch repos to get the latest version of restic, then raise an issue over at restic with reference to this thread for your suggestions on improving the completions script.

@krobelus
Copy link
Member

Yeah cobra generates fairly non-idiomatic completions, because they try to make fish behave like other shells.
Some bugs were fixed in spf13/cobra#1249, which was recently released with Cobra 1.2.0.
It's still unorthodox, but it should work for the most common cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants