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

Conversation

Projects
None yet
2 participants
@digitalatigid
Copy link
Contributor

digitalatigid 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
@faho
Copy link
Member

faho left a comment

Use the argparse, Luke!

end

function __fish_doas_no_subcommand
not __fish_doas_print_remaining_args >/dev/null

This comment has been minimized.

@faho

faho Sep 20, 2018

Member

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.

This comment has been minimized.

@digitalatigid

digitalatigid Sep 21, 2018

Contributor

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

This comment has been minimized.

@faho

faho Sep 20, 2018

Member

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.

This comment has been minimized.

@digitalatigid

digitalatigid Sep 21, 2018

Contributor

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"

This comment has been minimized.

@faho

faho Sep 20, 2018

Member

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

This comment has been minimized.

@digitalatigid

digitalatigid Sep 21, 2018

Contributor

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"

This comment has been minimized.

@faho

faho Sep 20, 2018

Member

"search for applying rules"?

This comment has been minimized.

@digitalatigid

digitalatigid Sep 21, 2018

Contributor

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"

This comment has been minimized.

@faho

faho Sep 20, 2018

Member

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".

This comment has been minimized.

@digitalatigid

digitalatigid Sep 21, 2018

Contributor

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

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@faho

This comment has been minimized.

Copy link
Member

faho commented Sep 25, 2018

Merged, thanks!

@faho faho added this to the fish-3.0 milestone Sep 25, 2018

@digitalatigid

This comment has been minimized.

Copy link
Contributor

digitalatigid commented Sep 26, 2018

yay, thanks ^-^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment