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

completions: add wg-quick #8687

Merged
merged 2 commits into from
Apr 18, 2022
Merged

Conversation

ammgws
Copy link
Contributor

@ammgws ammgws commented Feb 1, 2022

Description

Adds completions for the Wireguard wg-quick utility.

Fixes issue #

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

share/completions/wg-quick.fish Outdated Show resolved Hide resolved
set -l valid_subcmds up down strip save

function __wg_complete_interfaces
wg show 2>| string replace -rf 'Unable to access interface (.*): Operation not permitted' '$1'
Copy link
Member

Choose a reason for hiding this comment

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

Ooof, this seems... awkward. Is there really no better way than to parse an error message?

If you get an error message, is the argument actually useful?

Copy link
Contributor Author

@ammgws ammgws Feb 9, 2022

Choose a reason for hiding this comment

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

wg-quick looks for interfaces in /etc/wireguard/, which has 700 permissions so we cannot get completion candidates from there. This was the only way I could find that works - however I guess will need to prefix with LC_ALL=C too. wg show always shows the name of the currently connected interface in its error message, so it is perfect as the completion in this case.

Copy link
Member

Choose a reason for hiding this comment

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

wg-quick looks for interfaces in /etc/wireguard/, which has 700 permissions so we cannot get completion candidates from there.

Okay, wait... what happens if you are the owner (I'm assuming root?)?

What does wg show say then?

Copy link
Member

Choose a reason for hiding this comment

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

Ping @ammgws: Does this work if you're root? I'm assuming it doesn't error out then, but do the completions still work?

Copy link
Contributor Author

@ammgws ammgws Jun 23, 2022

Choose a reason for hiding this comment

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

@faho Sorry for the late reply. It doesn't error out, just gives garbage candidates for the completion:

>root@mydesktop ~# wg-quick down [TAB]
  allowed ips: 0.0.0.0/0, ::/0        private key: (hidden)                                   
  endpoint: xxx:51820                 public key: xxxx
  fwmark: 0xca6c                      transfer: 414.65 KiB received, 141.07 KiB sent          
  latest handshake: 50 seconds ago    interface: my_wg_interface                                    
  listening port: 49937               peer: xxxx

This is what it should parse when root to get the interface name:

>wg show interfaces
my_wg_interface

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually it looks like that works for non-root too, so we can just get rid of the kluge altogether:

>wg show
Unable to access interface mlvd-ch2: Operation not permitted
[1]>wg show interfaces
my_wg_interface

share/completions/wg-quick.fish Outdated Show resolved Hide resolved
@faho faho added this to the fish-future milestone Feb 8, 2022
@krobelus
Copy link
Member

krobelus commented Feb 9, 2022 via email

@faho faho merged commit 2a22a91 into fish-shell:master Apr 18, 2022
@faho
Copy link
Member

faho commented Apr 18, 2022

Merged, thanks!

@ammgws
Copy link
Contributor Author

ammgws commented Apr 19, 2022

Sorry I never got around to checking what happens when you're root

@zanchey zanchey modified the milestones: fish-future, fish 3.5.0 May 5, 2022
@ammgws ammgws deleted the wireguardcompletions branch June 17, 2022 00:06
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 26, 2023
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

4 participants