zquestz / s

Open a web search in your terminal.
MIT License
2.32k stars 114 forks source link

Fish completion #89

Closed ajm188 closed 8 years ago

ajm188 commented 8 years ago

Adds support for provider completion for fish shell.

KeizerDev commented 8 years ago

Please squash your commits to just one

ajm188 commented 8 years ago

@KeizerDev updated

KeizerDev commented 8 years ago

LGTM

ghost commented 8 years ago

@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)"
ajm188 commented 8 years ago

Is __fish_seen_subcommand_from a builtin?

ghost commented 8 years ago

Try,

type __fish_seen_subcommand_from

and let me know if you get any output.

ajm188 commented 8 years ago

Ok, cool. But let's say I did s -p amazon blah blah<TAB>, that would trigger the autocomplete, which is wrong. Right?

ghost commented 8 years ago

I don't know how s works, but why would that be wrong? I am trying your code, hold one a sec :smile:

ajm188 commented 8 years ago

(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.

ghost commented 8 years ago

This is the effect using your code AFIK:

s

Is this how s is supposed to behave?

ghost commented 8 years ago

And this is the effect using what I was suggesting.

s

ajm188 commented 8 years ago

Both of those actually look wrong to me. I don't think you can use two providers simultaneously. That wouldn't make sense.

ajm188 commented 8 years ago

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"

ghost commented 8 years ago

@ajm188 Alright, let me see, hold on another sec.

ghost commented 8 years ago

Is this closer?

s

ajm188 commented 8 years ago

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.

ghost commented 8 years ago

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:

s

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.

ghost commented 8 years ago

Edited my comment above. Cheers!

ajm188 commented 8 years ago

Hmm, I think I need to think about this some more. Everything seems wrong to me. Thanks for the input!

ghost commented 8 years ago

@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:

zquestz commented 8 years ago

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.