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

Closed
wants to merge 7 commits into from
Closed

Completions for snap #4215

wants to merge 7 commits into from

Conversation

radek-sprta
Copy link
Contributor

@radek-sprta 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

end

function __fish_snap_disabled_snaps --description 'List disabled snaps'
snap list | grep disabled | cut -d ' ' -f 1
Copy link
Member

Choose a reason for hiding this comment

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

I'd suggest using the string builtin here, and throughout the completion where you use grep/cut etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, switched to string everywhere.

@radek-sprta
Copy link
Contributor Author

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
Copy link
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
Copy link
Contributor Author

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
Copy link
Contributor Author

Should be feature complete now.

@radek-sprta radek-sprta changed the title [WIP] Completions for snap Completions for snap Jul 31, 2017
@krader1961
Copy link
Contributor

Squash merged as commit 74cac0f. Thx.

@krader1961 krader1961 closed this Aug 8, 2017
@krader1961 krader1961 added this to the fish 2.7.0 milestone Aug 8, 2017
@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

4 participants