Skip to content

📺 Add completions for fish shell#214

Merged
phatblat merged 1 commit intomas-cli:masterfrom
motohedgehog:fish-completion
Mar 5, 2019
Merged

📺 Add completions for fish shell#214
phatblat merged 1 commit intomas-cli:masterfrom
motohedgehog:fish-completion

Conversation

@motohedgehog
Copy link
Contributor

@motohedgehog motohedgehog commented Jan 29, 2019

This changeset adds completions for fish shell.
asciicast

Once this PR is approved, I would be happy to submit another one to also support fish in Homebrew formula.

@masclibot
Copy link

1 Message
📖 This PR might seem trivial, but every contribution counts. 😘

Generated by 🚫 Danger

@phatblat
Copy link
Member

@ylectric this is awesome! 🎉 I'm a fish shell user as well and this has been on my TODO list but I haven't gotten to it. Thanks!

This repo actually has a copy of the mas homebrew formula so that things like this can get added as part of a normal PR. Eventually, I hope to automate the formula updates from these source files:

Each of those files needs a fish_completion line if you would be so kind as to add them 🙏 .

I would think this file would need to get copied into ~/.config/fish/completions, but that appears to be for user-created files.

$ ls -l ~/.config/fish/completions
total 8
-rw-r--r--  1 ben                 18 Nov  4 09:38 fisher.fish

However, the fish docs say programs including completions should put them in the "vendor" dir which is system dependent.

$ pkg-config --variable completionsdir fish
/usr/local/share/fish/vendor_completions.d

$ ls -l /usr/local/share/fish/vendor_completions.d
total 0
lrwxr-xr-x  1 ben                 77 Nov 17 18:32 carthage.fish -> ../../../Cellar/carthage/0.31.2/share/fish/vendor_completions.d/carthage.fish
lrwxr-xr-x  1 ben                 66 Jan 29 21:42 hub.fish -> ../../../Cellar/hub/2.8.4/share/fish/vendor_completions.d/hub.fish

TL;DR

Turns out that Homebrew already takes care of this (see carthage).

@phatblat
Copy link
Member

this. is. amazing. 😍
screen shot 2019-01-29 at 10 08 31 pm

@motohedgehog
Copy link
Contributor Author

@phatblat Sorry, my bad, I didn't realise that formulae copies reside in this repo as well.

Homebrew ensures that completions are put into appropriate locations, so there's no fuss for us.
I will amend the formulae and submit an update.

I see --dry-run on your screenshot, does it mean that mas actually has flags? If so, is there any way to list them besides groking the sources? Also, I used a few lines of Python to generate fish completions, but I'm not familiar enough with XCode build systems to evaluate what would it take to make this process fully automated. What do you think?

@phatblat
Copy link
Member

Yes, several mas commands have switches, but not all of them. This project uses the Commandant framework to parse arguments and it also generates the help command output. You can use mas help <command> to see the options for any command.

$ mas help install
Install from the Mac App Store

(integer)
	app ID(s) to install

--force
	force reinstall

$ mas help uninstall
Uninstall app installed from the Mac App Store

(integer)
	ID of app to uninstall

--dry-run
	dry run

I'd love to see a script to auto-generate the shell completion files by parsing the help command output, but that should probably be in a separate PR.

If you want to grok the code, look in the MasKit/Commands/ directory. Each command will have a type conforming to OptionsProtocol (usually at the end of the file) which is where these flags get configured.

  • NoOptions is pretty obvious.
  • Argument declares positional arguments
  • Switch is for boolean flags where key is the --long form and flag is the short -l form (if non-nil)
  • Option is a --named argument

@motohedgehog
Copy link
Contributor Author

@phatblat Thank you for a thorough explanation. It should be enough to get the very first version of completions, and I may think about auto-generation later.

@motohedgehog
Copy link
Contributor Author

Alright, I amended Homebrew formulae and made completions for uninstall a little bit smarter.
asciicast

@motohedgehog
Copy link
Contributor Author

Jenkins failure looks unrelated, could you double check?

22:07:32 ==> 👢 Bootstrapping
22:07:32 /usr/local/opt/ruby/bin/bundle:23:in `load': cannot load such file -- /usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.0.1/exe/bundle (LoadError)
22:07:32 	from /usr/local/opt/ruby/bin/bundle:23:in `<main>'

@phatblat
Copy link
Member

phatblat commented Mar 2, 2019

Sorry! That was a temporary system issue on my build server. It's fixed now.

I love the fancy uninstall completion. Is this PR ready to go now?

@motohedgehog
Copy link
Contributor Author

@phatblat yes, absolutely :)

@phatblat phatblat merged commit 7c3951e into mas-cli:master Mar 5, 2019
@phatblat phatblat mentioned this pull request Mar 5, 2019
phatblat added a commit that referenced this pull request Mar 5, 2019
This was referenced Mar 31, 2019
@phatblat phatblat added this to the 1.6.3 milestone Feb 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants