Skip to content

jq: completion does not complete files when it should #510

Closed
@rrthomas

Description

@rrthomas

The current completion code tries to force the user to use a "mode" argument first, such as --slurp, by counting arguments, and only completing files when there are two or more arguments (including the command itself). However, the code as it stands does not count any mode arguments, so the number of arguments never exceeds 1 unless you manually type a file argument, so file arguments are never auto-completed.

Example session:

$ jq --sl<TAB>
$ jq --slurp # correct
$ jq --slurp <TAB> # nothing happens, should complete files

I had a look at the manual of jq to determine what these mode arguments are, because in theory adding a list of them as the third argument to _count_args would make the code work.

However, the concept of "mode" does not seem to exist in the manual. Indeed, no such argument is required. (You can run jq quite happily without any command-line option.)

So, I propose simply deleting the args-counting code, specifically this bit:

    local args
    # TODO: DTRT with args taking 2 options
    # -f|--from-file are not counted here because they supply the filter
    _count_args "" "@(--arg|--arg?(json|file)|--slurpfile|--indent|--run-tests|-!(-*)L)"

    # 1st arg is filter
    echo jq args: $args
    ((args == 1)) && return
    # 2... are input files

I am happy to make a PR if this is acceptable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions