Fish completion support #686
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What I'm trying to do and why
I'd like to have fish completion support for borgmatic. I went to write my own completions and noticed that the bash completions are generated automatically? It should be possible to output automatic completions in the same way for fish completions.
Other notes / implementation ideas
If there isn't interest in outputting completions automatically, it shouldn't be too hard to put it together by hand, the syntax is a lot nicer than bash completions. I don't understand the python being used to generate the bash completions or I would offer to make a PR.
It's also possible that taking advantage of fish completions nicer features, like specifying when file completions make sense, running code to get the possible options, and tagging flags with explanations would be easier / only possible by hand. I'm not sure what you have access to through this kind of introspection.
Environment
borgmatic version: 1.7.12
Use
sudo borgmatic --version
orsudo pip show borgmatic | grep ^Version
borgmatic installation method: [arch community package]
Borg version: 1.2.4
Use
sudo borg --version
Python version: 3.10.10
Use
python3 --version
operating system and version: 6.2.12-arch1-1
I'd be fully supportive of automatically generated Fish completions, but the reason I didn't do manual completions for Bash was because I didn't want to maintain them by hand as borgmatic flags change from version to version. And they do change pretty frequently.
In case it helps you do a PR for Fish completions, here's how the existing Bash completions code works—ignoring the actual Bash part:
In
borgmatic/commands/completion.py:bash_completion()
:create
,check
,prune
, etc.So in theory you could use a similar approach for generating Fish flags: It's basically just a loop over the borgmatic actions and the flags for each.
Let me know your thoughts.
This sounds great! Some of the "best" fish completions go further and do intellegent things--stuff like automatic completion for archive name when selecting an archive. This would be hard to automate, but I really don't think its needed.
You'd probably want to disable file completions at the top and then list all the commands and their flags automatically.
There is an open issue about how difficult it is to do flags for subcommands...
I went to look at fish completions I wrote before, and this one has conditional flags--flags that only are available if you pass other flags.
The git completions are referenced as an example of using flags for subcommands, but its horrific to look at...
d2f5daf8e8/share/completions/git.fish (L561-L593)
This stackoverflow answer might be a fine implementation and would be ok to embed at the top and use to set flags for only given subcommands.
So I think you'd get the global flags and register them (all in one line because you aren't putting a description), and then iterate each subcommand and register all the flags, and use one of the subcommand filtering functions.
If there was a way to get a description of the given command and flag I think it would be really nice...
I'm a little scared of mucking around with borgmatic on a system I also back up, but I'll take a shot at it when I get a bit more time. Thank you for your help!
Thanks again for your help understanding the python, I opened a pull request to add this feature--I don't write python, so I'm sorry if its not pythonic.
Implemented by @isaec in this PR: https://github.com/borgmatic-collective/borgmatic/pull/70
This will be part of the next release.
This was just released in borgmatic 1.7.13!