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 for snap #4215

Closed
wants to merge 7 commits into
base: master
from

Conversation

Projects
None yet
4 participants
@radek-sprta
Contributor

radek-sprta commented Jul 14, 2017

Description

Basic completions for snap. Still need to work out quirks with couple of the commands. Putting this here for feedback.

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
Show outdated Hide outdated share/completions/snap.fish Outdated
@radek-sprta

This comment has been minimized.

Show comment
Hide comment
@radek-sprta

radek-sprta Jul 18, 2017

Contributor

I ran into an issue with the snap connect/disconnect subcommands. The argument order is snap connect snap:interface.
I got it working to the point where it gives completions for snap and interface and results in snap connect snap: interface. Any idea how to get rid of the space after colon, that gets inserted after choosing a completion from the dropdown menu?

Contributor

radek-sprta commented Jul 18, 2017

I ran into an issue with the snap connect/disconnect subcommands. The argument order is snap connect snap:interface.
I got it working to the point where it gives completions for snap and interface and results in snap connect snap: interface. Any idea how to get rid of the space after colon, that gets inserted after choosing a completion from the dropdown menu?

@faho

This comment has been minimized.

Show comment
Hide comment
@faho

faho Jul 18, 2017

Member

The argument order is snap connect snap:interface.

So you mean the snap:interface is one token? Fish's completion works on one token at a time. What you want here is something like

complete -f -c snap -n '__fish_snap_using_subcommand connect' -a '(__fish_snap_connectable_snaps):(__fish_snap_interfaces)'

The two command substitutions will be combined in a cartesian product, so this should result in the correct thing.

If this however results in too many candidates, you can use commandline -ct and string match to check if there's a ":" in the current token. However, you then need to print the complete resulting token (e.g. printf '%s\n' (string replace -r '.*:' '' -- $token):(__fish_snap_interfaces)).

Member

faho commented Jul 18, 2017

The argument order is snap connect snap:interface.

So you mean the snap:interface is one token? Fish's completion works on one token at a time. What you want here is something like

complete -f -c snap -n '__fish_snap_using_subcommand connect' -a '(__fish_snap_connectable_snaps):(__fish_snap_interfaces)'

The two command substitutions will be combined in a cartesian product, so this should result in the correct thing.

If this however results in too many candidates, you can use commandline -ct and string match to check if there's a ":" in the current token. However, you then need to print the complete resulting token (e.g. printf '%s\n' (string replace -r '.*:' '' -- $token):(__fish_snap_interfaces)).

@radek-sprta

This comment has been minimized.

Show comment
Hide comment
@radek-sprta

radek-sprta Jul 20, 2017

Contributor

Thanks for the swift answer!
The Cartesian product would be too big I think (I was surprised how many interfaces were added since I last used snap), but I will try the second approach tonight.

Contributor

radek-sprta commented Jul 20, 2017

Thanks for the swift answer!
The Cartesian product would be too big I think (I was surprised how many interfaces were added since I last used snap), but I will try the second approach tonight.

@radek-sprta

This comment has been minimized.

Show comment
Hide comment
@radek-sprta

radek-sprta Jul 31, 2017

Contributor

Should be feature complete now.

Contributor

radek-sprta commented Jul 31, 2017

Should be feature complete now.

@radek-sprta radek-sprta changed the title from [WIP] Completions for snap to Completions for snap Jul 31, 2017

@krader1961

This comment has been minimized.

Show comment
Hide comment
@krader1961

krader1961 Aug 8, 2017

Contributor

Squash merged as commit 74cac0f. Thx.

Contributor

krader1961 commented Aug 8, 2017

Squash merged as commit 74cac0f. Thx.

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