GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add completions for CLI by lewisacidic · Pull Request #1118 · pre-commit/pre-commit

Conversation

@lewisacidic

@lewisacidic lewisacidic commented Aug 15, 2019

Copy link
Copy Markdown

Uses argcomplete to trivially add basic completions to the cli.

This allows things like:

$ pre-commit <TAB>
--help     -V          gc                install         run            uninstall
--version  autoupdate  help              install-hooks   sample-config
-h         clean       init-templatedir  migrate-config  try-repo

And

$ pre-commit install --hook-type <TAB>
commit-msg  pre-commit  pre-push  prepare-commit-msg

Which can be tab toggled through once the correct completions are registered (at least in fish, I didn't try other shells yet).

This is pretty basic (as might be expected from adding 2 simple lines of code!!!), it would be really nice to do a bit more, such as getting a list of the available hooks and completing pre-commit run <TAB> with them.

Also, at least with click CLIs, you should be able to get help messages showing up (in fish at least) which is nicer than this. Of course, this would require a rewrite of the parser code to use click...

Any opinions about this sort of functionality?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@lewisacidic
feat(main): add completions to cli
c3068fe
Uses `argcomplete` to add basic completions to the cli.
@asottile

asottile commented Aug 15, 2019

Copy link
Copy Markdown
Member

sorry, don't really want to add a dependency for this

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@asottile

asottile commented Aug 15, 2019

Copy link
Copy Markdown
Member

also the strategy used by argcomplete is too slow to be useful, it adds ~200ms per <tab> press which is well past the noticeable "slowness"

I believe the more correct way to do something like this would be to pregenerate completions as part of the packaging and provide those separately

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lewisacidic

lewisacidic commented Aug 15, 2019

Copy link
Copy Markdown
Author

Thanks for the quick reply.

In my opinion completions are pretty important for friendly, usable CLI tools. I understand pre-commit isn't first and foremost a CLI tool, but I found I missed completions when I was trying to remember how to install a commit-msg hook just now (typing -h is too much for me :))

I guess we could write completions by hand for the relatively small number of available commands and not need any new dependencies, but this is definitely the easiest and most integrated way to provide completions.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@asottile

asottile commented Aug 15, 2019

Copy link
Copy Markdown
Member

it's not particularly difficult to generate completions scripts, here's some prior art: https://github.com/asottile/all-repos/blob/master/all_repos/complete.py

Would expose some command like:

eval "$(pre-commit complete)"

which you could put in your rc file

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lewisacidic

lewisacidic commented Aug 15, 2019

Copy link
Copy Markdown
Author

Just seen your followups, yep it's laggy (tbh I'm using WSL so I'm used to laggy terminals, didn't really notice...). I think the lag could be alleviated with a refactor to avoid importing before parsing CLIs, I've used this style of autocompletion before and it worked a charm.

In any case, I don't really have the time to invest into writing anything substantial right now, shall I close this and open an issue about completions instead?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@asottile

asottile commented Aug 15, 2019

Copy link
Copy Markdown
Member

yeah I don't really want to play the import whackamole game -- there's not a good reason to runtime-compute completions when we can generate them all statically

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@asottile asottile closed this Aug 15, 2019
@lewisacidic lewisacidic mentioned this pull request Aug 15, 2019
Completions for CLI #1119
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@lewisacidic @asottile
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.