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 completion for prime-run #7241

Merged
merged 1 commit into from Aug 10, 2020
Merged

Conversation

oriko1010
Copy link
Contributor

Description

Simple completion for the prime-run script.

TODOs:

  • Changes to fish usage are reflected in user documentation/manpages.
  • Tests have been added for regressions fixed
  • User-visible changes noted in CHANGELOG.rst

@@ -0,0 +1,6 @@
function __fish_complete_prime_run_subcommand
set -lx -a PATH /usr/local/sbin /sbin /usr/sbin
__fish_complete_subcommand --commandline $args
Copy link
Member

Choose a reason for hiding this comment

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

$args should be something like (commandline -opc)[2..], or else it will only complete the command name - try
prime-run grep -- and press Tab. (Though this doesn't seem terribly important here.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

$ prime-run grep --[TAB]
--after-context                          (Print NUM lines of trailing context)
--basic-regexp                                        (Pattern is basic regex)
...

Unless you're referring to something else, this does seem to work for me. I used the sudo completion as a guide. Though now I realized the $args probably isn't even necessary, as prime-run has no arguments of its own.

Copy link
Member

@krobelus krobelus Aug 10, 2020

Choose a reason for hiding this comment

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

Oh I see, this happens to work because

  • $args is undefined here, so it is an empty list (the parameters to a function are in $argv)
  • In __fish_complete_subcommand.fish, $subcommand is set to the empty list.
  • As a result the subcommand to complete is based off (commandline -cop) (commandline -ct) which is the current command line left of the cursor.

Yep, the --commandline option is useful for passing a custom commandline when completing commands like sudo that accept options on their own.
Merged as 8b02a78 with the simplification in 46a69d6, thanks!

@krobelus krobelus merged commit 8b02a78 into fish-shell:master Aug 10, 2020
@krobelus krobelus added this to the fish 3.2.0 milestone Aug 10, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants