The Wayback Machine - https://web.archive.org/web/20221013222238/https://github.com/unisonweb/unison/issues/2467
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

UCM bash/zsh completion support #2467

Open
ChrisPenner opened this issue Oct 6, 2021 · 5 comments
Open

UCM bash/zsh completion support #2467

ChrisPenner opened this issue Oct 6, 2021 · 5 comments
Labels
cli feature request good first issue A good first issue for new contributors

Comments

@ChrisPenner
Copy link
Contributor

ChrisPenner commented Oct 6, 2021

In #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
  1. 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.
@ChrisPenner ChrisPenner added cli feature request good first issue A good first issue for new contributors labels Oct 6, 2021
@ceedubs
Copy link
Contributor

ceedubs commented Oct 8, 2021

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

ceedubs commented Oct 8, 2021

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

aryairani commented Oct 8, 2021

Built January 1, 1980?

@ceedubs
Copy link
Contributor

ceedubs commented Oct 8, 2021

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

ceedubs commented Aug 17, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli feature request good first issue A good first issue for new contributors
Projects
None yet
Development

No branches or pull requests

3 participants