Skip to content

Shell completion overhaul #678

Open
Open
@rgoldberg

Description

@rgoldberg

mas 1.8.7+ uses Swift Argument Parser (aka SAP), which can generate shell completion scripts for bash, fish & zsh.

Scripts for mas would be written to stdout by running:

mas --generate-completion-script <bash | fish | zsh>

The completion scripts generated by the current version of SAP (1.5.0), however, suffer from many problems.

I have opened 2 issues in SAP. I've submitted a PR for the first, and am finishing a PR for the second:

If SAP does not merge & release the associated PRs quickly, mas can depend on a branch off main in an mas fork of SAP that contains the aforementioned 2 PRs.

Once all SAP improvements are ready:

  • remove the existing bash & fish completion scripts from git
  • setup mas to generate completion scripts for all 3 shells using SAP
  • generate all 3 scripts in:
    • Homebrew/core/mas formula
    • mas-cli/tap/mas formula
    • *.pkg installation process
    • any other installation process
  • document completion script generation in README.md
  • possibly create a new command / option to write scripts for all three shells (or maybe just one at a time based on an argument) to their proper locations to be loaded by their respective shell & used for completion.
  • discontinue app names as arguments for mas upgrade
    • remove AppLibrary.installedApps(named:)
  • Remove lucky after providing replacements #608
  • Offer subcommands as completions after mas help

Assuming that bundle IDs are supported as arguments optionally in place of app IDs (see #541; app IDs & bundle IDs will be collectively termed IDs), completion for IDs would work as follows:

For commands that work on installed apps:

If the current word contains all digits, match against installed app IDs, then offer them as completions, annotated with the associated app name & bundle ID.

Otherwise, match against installed bundle IDs, then offer them as completions, annotated with the associated app name & app ID.

Also, search the installed app names for the text of the current word. Offer the bundle ID as the completion for each result (ordered as per the response from Apple), each annotated with the app name & app ID.

The above completion candidates would be filtered as relevant to the current command. e.g., only IDs of outdated apps would be offered for mas upgrade.

For commands that work on apps that aren't installed:

Search the Apple iTunes Store Web API for the text of the current word. Offer the bundle ID as the completion for each result (ordered as per the response from Apple), each annotated with the app name & app ID.

Supersede:

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions