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 completions for openbsd's doas #5196

Merged
merged 3 commits into from Sep 25, 2018
Merged

Add completions for openbsd's doas #5196

merged 3 commits into from Sep 25, 2018

Conversation

ghost
Copy link

@ghost ghost commented Sep 19, 2018

TODOs:

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

Copy link
Member

@faho faho left a comment

Choose a reason for hiding this comment

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

Use the argparse, Luke!

end

function __fish_doas_no_subcommand
not __fish_doas_print_remaining_args >/dev/null
Copy link
Member

Choose a reason for hiding this comment

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

Conditions are already silenced, so there's no real need for this redirection and therefore function in general - just -n "not __fish_doas_print_remaining_args" works.

Copy link
Author

Choose a reason for hiding this comment

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

this is from the sudo completions :P I'll remove the function then.

# we want.
if test -n "$argv"
and not string match -qr '^-' $argv[1]
echo $argv
Copy link
Member

Choose a reason for hiding this comment

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

This output isn't currently used, though I'd imagine you'll want to do so - see the sudo completions.

The reason that does the echo is because it then uses that for complete -C (--do-complete=), which is better than using the stock __fish_complete_subcommand function because it used argparse to remove the options.

As an illustration of this general problem, imagine you had

git -C log status

as your commandline. What is the command here? If you knew nothing about git, you'd say log, with status being an argument to it and -C being a boolean flag. But actually the command is status, because log is an argument to the -C option.

That's why argparse is useful, because it can solve those cases. You're almost there, but you need to do the last step.

Copy link
Author

Choose a reason for hiding this comment

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

I'll have a closer look at this. This is my first time writing completions and I couldn't find much documentation about it, so this is based on other completions.

not __fish_doas_print_remaining_args >/dev/null
end

complete -c doas -n "__fish_doas_no_subcommand" -s a -d "Choose auth method on openbsd systems"
Copy link
Member

Choose a reason for hiding this comment

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

"on openbsd systems" meaning this isn't implemented elsewhere?

Copy link
Author

Choose a reason for hiding this comment

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

it's used on other systems than openbsd. I didn't feel the need to give an exhaustive list and was doing this based on the openbsd manpage, so I went with that. I'll change it to be system agnostic.
(I'm using a linux port of doas currently, so this is a bit confusing.)

end

complete -c doas -n "__fish_doas_no_subcommand" -s a -d "Choose auth method on openbsd systems"
complete -c doas -n "__fish_doas_no_subcommand" -s C -r -d "Parse and check given config file, then search for applying rules"
Copy link
Member

Choose a reason for hiding this comment

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

"search for applying rules"?

Copy link
Author

Choose a reason for hiding this comment

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

With the -C flag, doas will look through it's configuration and see if any rule matches the supplied command. it will then print out what kind of rule matched.


complete -c doas -n "__fish_doas_no_subcommand" -s a -d "Choose auth method on openbsd systems"
complete -c doas -n "__fish_doas_no_subcommand" -s C -r -d "Parse and check given config file, then search for applying rules"
complete -c doas -n "__fish_doas_no_subcommand" -s L -d "Clear persisted authorizations, then immeadiately exit. No command is exectued"
Copy link
Member

Choose a reason for hiding this comment

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

Does it execute anything? I'm not quite sure 😄.

Descriptions should be kept short, so I'd say something like:

Clear persisted authorizations and exit

Alternatively sudo calls this "removing cached credentials".

Copy link
Author

Choose a reason for hiding this comment

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

doas does what sudo does, but it's configuration is waay simpler and understandable.
I just copied the doas man page here :)

@faho faho merged commit 794b448 into fish-shell:master Sep 25, 2018
@faho
Copy link
Member

faho commented Sep 25, 2018

Merged, thanks!

@faho faho added this to the fish-3.0 milestone Sep 25, 2018
@ghost
Copy link
Author

ghost commented Sep 26, 2018

yay, thanks ^-^

@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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant