Skip to content

Feature Request: Minimalistic tab-completion with descriptions #99

@am11

Description

@am11

Recent improvements (see commit acae889 by @rmyorston]) added basic tab completion for builtins, functions, and aliases in ash.

It would be great to extend this with static registration of completions, allowing interactive CLI tools to provide context-aware completions similar to zsh and pwsh.

e.g. here is how the zsh completion for deno(1) looks like:

zsh / cat /opt/homebrew/share/zsh/site-functions/_deno 
#compdef deno

autoload -U is-at-least

_deno() {
    typeset -A opt_args
    typeset -a _arguments_options
    local ret=1

    if is-at-least 5.2; then
        _arguments_options=(-s -S -C)
    else
        _arguments_options=(-s -C)
    fi

    local context curcontext="$curcontext" state line
    _arguments "${_arguments_options[@]}" : \
'--no-check=[Skip type-checking. If the value of "remote" is supplied, diagnostic errors from remote modules will be ignored]' \
'--import-map=[Load import map file from local file or remote URL   Docs\: https\://docs.deno.com/runtime/manual/basics/import_maps]:FILE:_files' \
'--node-modules-dir=[Sets the node modules management mode for npm packages]' \
'--vendor=[Toggles local vendor folder usage for remote modules and a node_modules folder for npm packages]' \
'-c+[Configure different aspects of deno including TypeScript, linting, and code formatting   Typically the configuration file will be called \`deno.json\` or \`deno.jsonc\` and   automatically detected; in that case this flag is not necessary.>
'--config=[Configure different aspects of deno including TypeScript, linting, and code formatting   Typically the configuration file will be called \`deno.json\` or \`deno.jsonc\` and   automatically detected; in that case this flag is not nece>
'*-r+[Reload source code cache (recompile TypeScript)   no value                                                 Reload everything   jsr\:@std/http/file-server,jsr\:@std/assert/assert-equals  Reloads specific modules   npm\:                    >
'*--reload=[Reload source code cache (recompile TypeScript)   no value                                                 Reload everything   jsr\:@std/http/file-server,jsr\:@std/assert/assert-equals  Reloads specific modules   npm\:              >
'--lock=[Check the specified lock file. (If value is not provided, defaults to "./deno.lock")]' \
'--cert=[Load certificate authority from PEM encoded file]:FILE:_files' \
'--unsafely-ignore-certificate-errors=[DANGER\: Disables verification of TLS certificates]' \
'*-R+[Allow file system read access. Optionally specify allowed paths]' \
'*--allow-read=[Allow file system read access. Optionally specify allowed paths]' \
...

and tab completion on subcommand shows them with description:
Image

Proposal for ash

  • Introduce a directory (/etc/ash/completion.d/) where scripts can define completions.
  • Format similar to zsh (option[Description]), parsed minimally.

I think static completion is more aligned with busybox's minimalistic approach than dynamic registration mechanism (which requires more utilities / phases). Static is basically: search all lines in completion file which begin with the subcommand and display them with description.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions