Closed ajm188 closed 8 years ago
Please squash your commits to just one
@KeizerDev updated
LGTM
@KeizerDev @ajm188 Instead of creating __fish_s_needs_option_argument
, you can use fish
__fish_seen_subcommand_from
which seems enough for this simple use case.
function __fish_s_provider_list
find $GOPATH/src/github.com/zquestz/s/providers -depth 1 -type d | sed 's:.*/::'
end
complete -f -c s -s p
complete -f -c s -n '__fish_s_needs_option_argument -p' -a '(__fish_s_provider_list)'
complete -xc s -n "__fish_seen_subcommand_from -p" -a "(__fish_s_provider_list)"
Is __fish_seen_subcommand_from
a builtin?
Try,
type __fish_seen_subcommand_from
and let me know if you get any output.
Ok, cool. But let's say I did s -p amazon blah blah<TAB>
, that would trigger the autocomplete, which is wrong. Right?
I don't know how s
works, but why would that be wrong? I am trying your code, hold one a sec :smile:
(It's in the docs): s supports searching by providers, so I can say s -p amazon <search>
, to search amazon directly. The autocompletion is just for the providers. So, if I use __fish_seen_subcommand_from
, it's checking that I used -p
at all, where my code is checking that I'm currently in the process of typing the argument to -p
.
Edit: at least, this is my current understanding. If I'm wrong, please correct me.
This is the effect using your code AFIK:
Is this how s
is supposed to behave?
And this is the effect using what I was suggesting.
Both of those actually look wrong to me. I don't think you can use two providers simultaneously. That wouldn't make sense.
The code I was trying to write was something to the effect of "if -p is the last thing you typed, or if you are typing the word immediately after -p, then we should do completion"
@ajm188 Alright, let me see, hold on another sec.
Is this closer?
I can't tell if it's completing the "x" multiple times, and also I would say the "-p" shouldn't be able to appear twice.
I don't think you can't prevent short options like -p
from appearing multiple times, because a utility could have more than one short option and they are sometimes joinable.
For example, npm
:
You should not be able to type --save
twice, as that does not make sense, but you can't really avoid it.
This is too difficult or impossible to do in fish
.
Wrong, your
__fish_s_needs_option_argument
does do it, kind of.
As for x
appearing multiple times, yup, that can be done.
Edited my comment above. Cheers!
Hmm, I think I need to think about this some more. Everything seems wrong to me. Thanks for the input!
@ajm188 Ha! Please let me know if you figure out exactly what you needed or whatever you come up as I am interested too. Ping me or send me an email to the address listed on my profile page.
:+1:
I made minor adjustments in master already. However I am happy to take a revision PR. I don't use fish so I didn't test it super extensively. zsh user here.
Adds support for provider completion for fish shell.