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

Completion for conda, the package manager #4837

Merged
merged 8 commits into from Mar 26, 2018

Conversation

Projects
None yet
2 participants
@luc-j-bourhis
Copy link
Contributor

luc-j-bourhis commented Mar 19, 2018

I propose completion for the package manager conda. Since fish ships with support for completing brew, pacaur, pip, etc, I think it is appropriate to also include the rather popular conda.

# Complete using -n to select the given conda subcommand
# and passing the rest of the arguments to `complete`
# The goal here is to reduce clutter in the definitions below
# This function will be deleted at the end

This comment has been minimized.

@faho

faho Mar 25, 2018

Member

That's probably not fantastic since the name is so generic.

If the user has a function with that name, you'll first redefine and then delete it.

This comment has been minimized.

@faho

faho Mar 25, 2018

Member

Call it __conda or something.

This comment has been minimized.

@luc-j-bourhis

luc-j-bourhis Mar 25, 2018

Contributor

Addressed by 4b45243


# Option name
for cmd in create install list remove search update
if test $cmd = create

This comment has been minimized.

@faho

faho Mar 25, 2018

Member

Move create out of the for-loop since there's no shared part.

This comment has been minimized.

@luc-j-bourhis

luc-j-bourhis Mar 25, 2018

Contributor

Addressed by 64d5b94

function __fish_conda_needs_command -a cmd
# We need to filter out -x and --xx options so as to complete
# the arguments of said options
test (string match -r '^\w+' -- (commandline -opc))[-1] = $cmd

This comment has been minimized.

@faho

faho Mar 25, 2018

Member

I'd be really careful with test - it has some surprisingly sharp edges. This'll fail when the command substitution returns nothing, and it effectively does the same thing __fish_use_subcommand does.

We do have __fish_seen_subcommand_from, which just tests if a given word has been given. Usually I'll do not __fish_seen_subcommand_from $allcmds (where $allcmds contains all the subcommands that the command accepts).

That's still not perfect, because it'll see something like git -C log as using the "log" subcommand instead of the argument to the "-C" option. To do it properly, you need to actually know which options accept arguments - see how the git or systemctl completions do it - kinda complicated, right?

This comment has been minimized.

@luc-j-bourhis

luc-j-bourhis Mar 25, 2018

Contributor

Addressed by 10ff253

@faho faho added this to the fish-3.0 milestone Mar 25, 2018

luc-j-bourhis added some commits Mar 25, 2018

Use Use __fish_seen_subcommand_from to identify subcommand
And treat the case of the first argument as a special case
with function __fish_conda_fist_arg

@luc-j-bourhis luc-j-bourhis force-pushed the luc-j-bourhis:conda branch from 8760b98 to 64d5b94 Mar 25, 2018

@faho

faho approved these changes Mar 26, 2018

@faho faho merged commit c116843 into fish-shell:master Mar 26, 2018

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@faho

This comment has been minimized.

Copy link
Member

faho commented Mar 26, 2018

Nice, merged!

@luc-j-bourhis luc-j-bourhis deleted the luc-j-bourhis:conda branch Mar 26, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment