Allow handing of completion by an external command's shell completion

Open
#774 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Quiet
Tech stack
fish, rust, shell
Domain
cli, tooling

Research direction

Start by tracing usage's existing completion handling and the shell-framework entry points it already supports. Compare the requested external-command flow with the current complete and arg var=#true model, including how words belonging to the command argument are passed onward. Done means a defined approach for delegated completion, support for nested arguments such as terraform plan -o, and coverage for the supported shell frameworks.

Written by the indexing model from the issue text.

Description

We have a wrapper script around terraform and it would be nice to be able to profit from the completion available for the wrapped command.

What we currently do:

arg "<layer>" help="Layer to run"
arg "<command>" var=#true help="Terraform command to run"
complete "command" descriptions=#true run=#"terraform -help 2>&1 | awk '/^  [a-z]/ {cmd=$1; $1=""; sub(/^ +/,""); print cmd":"$0}'"#

It would be nice if the completion could not require awk and support further stuff like terraform plan -o completing to -out.

To demonstrate what would need to happen technically (with fish as an example):

arg "<layer>" help="Layer to run"
arg "<command>" var=#true help="Terraform command to run"
complete "command" descriptions=#true run=#"fish -c 'complete -C "terraform {{words[CURRENT]}"'"#
// The `words[CURRENT]` is not really correct, as we need all the words that belong to the `command` arg for this to work properly.
// (I don't know if that is currently possible)

As usage already must be aware of all the completion frameworks it supports, I feel like handing that over would be natural.

I am not sure that the arg var=#true style to model this situation is the best way to support this new functionality. I just chose this to bring the point across.

Dominant language
Rust
Stars
1k
Forks
59
Avg merge
5h 58m
Merged PRs (30d)
362

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from jdx/usage

All issues in jdx/usage

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.