Skip to content

Completion for conda, the package manager - #4837

Merged
faho merged 8 commits into
fish-shell:masterfrom
luc-j-bourhis:conda
Mar 26, 2018
Merged

faho merged 8 commits into
fish-shell:masterfrom
luc-j-bourhis:conda

Conversation

@luc-j-bourhis

Copy link
Copy Markdown
Contributor

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.

Comment thread share/completions/conda.fish Outdated
# 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Call it __conda or something.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed by 4b45243

Comment thread share/completions/conda.fish Outdated

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed by 64d5b94

Comment thread share/completions/conda.fish Outdated
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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed by 10ff253

@faho faho added enhancement completions release notes Something that is or should be mentioned in the release notes labels Mar 25, 2018
@faho faho added this to the fish-3.0 milestone Mar 25, 2018
@faho
faho merged commit c116843 into fish-shell:master Mar 26, 2018
@faho

faho commented Mar 26, 2018

Copy link
Copy Markdown
Member

Nice, merged!

@luc-j-bourhis
luc-j-bourhis deleted the conda branch March 26, 2018 15:26
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

completions enhancement release notes Something that is or should be mentioned in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants