unisonweb / unison

A friendly programming language from the future
https://unison-lang.org
Other
5.81k stars 271 forks source link

UCM bash/zsh completion support #2467

Open ChrisPenner opened 3 years ago

ChrisPenner commented 3 years ago

In https://github.com/unisonweb/unison/pull/2280, I swapped ucm to use optparse applicative, which means we can now get Bash, Zsh, or Fish tab-completion on arguments and commands for free! This also allows configuring custom completion types within the CLI code, and if you use the appropriate parser type for arguments it can infer that a given argument must be a file or directory, etc.

You can read about it here, but I believe all that we need to do is:

  1. Run the built ucm executable with the following commands as part of the release process:
    • ucm --zsh-completion-script $(which ucm) > zsh_completion.sh
    • ucm --bash-completion-script $(which ucm) > bash_completion.sh
  2. Load the generated completion scripts into the appropriate directory as part of the homebrew installation process. It'll just take a bit of reading to determine where and how to load those where they need to go.
ceedubs commented 3 years ago

Thanks for the tip, @ChrisPenner! And also for the switch to optparse applicative.

I don't know much about Homebrew, but I set this up in the Nix derivation for ucm and it seems to be working well. Here is the directory structure that I'm using, which I think follows the conventions for the various shells (I don't know if share would be parent directory in homebrew though).

share
├── bash-completion
│   └── completions
│       └── ucm.bash
├── fish
│   └── vendor_completions.d
│       └── ucm.fish
└── zsh
    └── site-functions
        └── _ucm
ceedubs commented 3 years ago

I just realized that we can also auto-generate a not-completely-terrible man page for ucm thanks to optparse-applicative generating a useful --help:

help2man --no-info -v version ucm | nroff -man

Output ``` UCM(1) User Commands UCM(1) NAME ucm - manual page for ucm version: release/M2j (built on 2021-10-07) SYNOPSIS ucm [--codebase codebase/path | --codebase-create codebase/path] DESCRIPTION ???? [1mUsage instructions for the Unison Codebase Manager[0m You are run- ning version: release/M2j (built on 2021-10-07) To get started just run [1mucm[0m Use [1mucm [command] --help[0m to show help for a command. [COMMAND | [--token STRING] [--host STRING] [--port NUMBER] [--ui DIR] [--no-base]] Available options: --codebase codebase/path The path to an existing codebase --codebase-create codebase/path The path to a new or existing codebase (one will be created if there isn't one) --token STRING API auth token --host STRING Codebase server host --port NUMBER Codebase server port --ui DIR Path to codebase ui root --no-base if set, a new codebase will be created without downloading the base library, otherwise the new codebase will download base -h,--help Show this help text Available commands: version Print the version of unison you're running init This command is has been removed. Use --codebase-create instead to create a codebase in the specified directory when starting the UCM. run Execute a definition from the codebase run.compiled Execute previously compiled output run.file Execute a definition from a file run.pipe Execute code from stdin transcript Execute transcript markdown files transcript.fork Execute transcript markdown files in a sandboxed codebase headless Runs the codebase server without the command-line interface. ucm version: release/M2j (built oJanuary11980) UCM(1) ```
aryairani commented 3 years ago

Built January 1, 1980?

ceedubs commented 3 years ago

Built January 1, 1980?

Haha. My guess would be that this has to do with git or Nix normalizing a date for reproducibility/consistent hashing. But I have no idea why it would differ from what's at the top of the page. 🤷

ceedubs commented 2 years ago

I found an example of a project that installs shell completion as part of its homebrew formula.

I don't know homebrew or Ruby well enough to understand whether the homebrew formula could call into ucm to generate these files as part of the installation. Or would they need to be bundled into the tar file?

Does anyone who uses homebrew want to give this a try? This is the Homebrew formula that you'd need to change.