📺 Add zsh completions
#222 has been open for over 5 years now (🥳 congrats). About time someone took care of it, especially as it's the default shell.
Closes #222
Please let me know of any questions/suggestions you might have.
Let me know if any of these reviews are an actual concern as most aren't applicable.
Been busy lately, but I've finally gotten time to come back to this pr.
I've changed it so the output from mas search, mas list, and mas outdated are all parsed into an array of ids and names such that an associative array can be constructed from the data. The other functions now pick the data they need from this array.
__mas_list_outdated also no longer suggests the name or id of any apps which have already been specified.
Thanks for taking the time to review!
@Logicer16 Thanks. I'll check out the new version in a few days.
I am currently working on switching from Commandant to Swift Argument Parser for multiple reasons, one of which is that it can autogenerate completion scripts for zsh, bash, and fish.
Once I'm done with it locally (I won't open any new PRs until an existing PR that fixes a breaking lint issue in main is merged), I'll compare the generated script to yours. If yours is better, I'll see if we can automate modifying the generated one to add your features, as it would be useful to be able to autogenerate competitions for all 3 shells whenever we release a new version instead of having to hand code things & to manually ensure that completion remains in sync with the executable.
@Logicer16 I have a working local branch in which I've switched from Commandant to Swift Argument Parser (SAP).
I've begun to look into SAP generating completion scripts for zsh, bash & fish.
It seems like the nicest way to provide custom completions for all 3 shells is to define them in Swift code. When wired via Swift attributes, the generated completion scripts call mas with special arguments to run the specified Swift function, so all of the logic only needs to be implemented once in Swift, instead of once each in zsh, bash & fish.
Moreover, we'll probably switch to outputting JSON from an internal Swift executable to an mas wrapper script. JSON will be formatted into tabular output in the wrapper, so even if we were to implement completion in shell instead of in Swift, we'd parse everything from JSON output instead of tabular output.
I'll leave this PR open, but we'll probably use the SAP completions.
Sorry that you did work that probably won't be merged, but you'll receive a much more maintainable mas this way.
No matter what, we need to wait for @phatblat to release new versions; I should have SAP completion script generation ready before we can release, so you shouldn't see any delay in getting zsh completion released between the SAP-generated script versus if we had merged your hand-coded completion.
All good.
I agree, it would be much simpler to have everything defined in swift. Looking through their documentation, it should be possible to achieve feature parity with what's in this pr.
Regardless, with the amount I've learned about zsh in the process, I don't see this as time wasted.
Thanks for your time.
Thanks for your time & effort, too.
The SAP-generated zsh completion script is slightly wrong for the auto-created help subcommand, --help flag, and -h flag. I'm looking into reconfiguring the synthesized help functionality & completion, and into submitting PRs to SAP to fix the issue.