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
Provide completions for s3cmd #4332
Conversation
No longer auto-generated. Everything has been summarized. Supressing file completions for initial command, providing list of valid initial commands, filtering --options by subcommand.
9193a36
to
497f40a
Compare
share/completions/s3cmd.fish
Outdated
# s3cmd | ||
|
||
function __s3cmd_is_remote_path | ||
commandline -pct | string match -r -- "^s3://.*" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll usually want to use the "-q" flag for string match
.
It's okay here since this is only used as a complete condition, which has its output already silenced.
share/completions/s3cmd.fish
Outdated
function __prev_tokens | ||
set __tokens (commandline -pco) | ||
for arg in $argv | ||
if echo $__tokens[-1] | string match $arg |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string match -q -- $argv $__tokens[-1]
- the echo
is unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, this is basically __fish_seen_subcommand_from
.
share/completions/s3cmd.fish
Outdated
|
||
function __initial_command | ||
set __tokens (commandline -pco) | ||
string match (count $__tokens) 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit unorthodox.
Strictly, this would be set -q __tokens[1]; and not set -q __tokens[2]
. You could probably get by without the first check, depending on what exactly you want to do with this.
Alternatively, test (count $__tokens) = 1
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is also __fish_is_first_token
already. That one skips options.
Personally, for subcommands, I prefer not __fish_seen_subcommand_from $cmds
(see e.g. the systemctl completions). That allows for options and option-arguments, as long as they don't look like a command.
For a completely correct solution, you're going to need to do something like the git completions, or use argparse (which I'm converting both the git and systemctl completions to).
@faho thanks for reviewing; I knew there would be a significant amount of feedback if I opened this a PR rather than merging directly despite the fact that it works. I had a hard time finding a good reference on the best practices for writing completions and each completion file I looked at was different than the other (though of course I didn't go through too many). Perhaps we can add a more-indepth article about writing completions to the online resources, as the existing seemed to only cover the very basic usage of I didn't look at the completions for sysctl, I tried to base mine off of It doesn't seem like it should be too hard to take these suggestions into account (I'm going to hold off on |
Yes, they are. They were written at different times by different people. Obviously I prefer my own style.
That would be nice to have, yes.
Note: The completions for it are nice (except for the use of
Sure.
Yes. You can push directly to Integration_2.7.0 if you want - no need to review again, unless you prefer that. In its current state this is okay, my objections are stylistic. |
OK, thanks again. |
…tions Per the discussion with @faho in fish-shell#4332, replaced some custom completion state detection functions with standard __fish_* functions used in other completion sources.
No longer auto-generated. Everything has been summarized. Supressing
file completions for initial command, providing list of valid initial
commands, filtering --options by subcommand.