Skip to content
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

Add support for shell-completions file generation #76

Merged
merged 2 commits into from
Aug 31, 2023

Conversation

Coruscant11
Copy link
Contributor

@Coruscant11 Coruscant11 commented Aug 30, 2023

Closes #67

Hello @bradlarsen ! 👋
I worked on this very tiny issue for fun if you don't mind.
As you suggested in the issue, I used arg_complete.

A future improvement would be to generate these completion files at compile time, with the build.rs.
https://docs.rs/clap_complete/latest/clap_complete/generator/fn.generate_to.html

By installing Nosey Parker with an install script (package or cargo install for example), or even inside a Docker image, we could add auto-completion at install time.

Usage

noseyparker shell-completions --shell SHELL

If you quickly test with zsh for example :

noseyparker shell-completions --shell=zsh > noseyparker.zsh
source noseyparker.zsh

If you want to permanently add the completions to bash on Linux :

noseyparker shell-completions --shell=bash > noseyparker.bash
sudo mv noseyparker.bash /usr/share/bash-completion/completions/

Example

There is five possible values for the shell format :

➜  noseyparker git:(feat/clap_complete) ✗ noseyparker shell-completions --shell
error: a value is required for '--shell <SHELL>' but none was supplied
  [possible values: bash, zsh, fish, powershell, elvish]

For more information, try '--help'.

Here is the look when you toggle TAB for example for just noseyparker with zsh :

➜  noseyparker git:(feat/clap_complete) ✗ noseyparker
datastore          -- Manage datastores
github             -- Interact with GitHub
help               -- Print this message or the help of the given subcommand(s)
report             -- Report detailed scan findings
rules              -- Manage rules
scan               -- Scan content for secrets
shell-completions  -- Generate shell completions
summarize          -- Summarize scan findings

Or with shell-completions --shell :

➜  noseyparker git:(feat/clap_complete) ✗ noseyparker shell-completions --shell=
bash        elvish      fish        powershell  zsh

Completions seems to work for every commands.
I tested with zsh and bash.


Can you tell me if I should fix something ? 😄
Thanks !

@bradlarsen bradlarsen self-requested a review August 31, 2023 12:31
@bradlarsen
Copy link
Collaborator

@Coruscant11 thanks for doing this! I will review this soon!

bradlarsen
bradlarsen previously approved these changes Aug 31, 2023
Copy link
Collaborator

@bradlarsen bradlarsen left a comment

Choose a reason for hiding this comment

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

This looks perfect! I'm just going to update the CHANGELOG to credit you, @Coruscant11 . Thank you!

@bradlarsen bradlarsen merged commit d444388 into praetorian-inc:main Aug 31, 2023
6 checks passed
@bradlarsen bradlarsen added enhancement New feature or request ux Related to the user experience, invocation, or CLI labels Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request ux Related to the user experience, invocation, or CLI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bash/Fish/Zsh completions?
2 participants