From 6c09f2a45c5541e9c207d14fc7aa21a4a0066bde Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 4 May 2024 03:03:19 +0200 Subject: Merging upstream version 1:2.12.0. Signed-off-by: Daniel Baumann --- completions/jq | 55 ++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 40 insertions(+), 15 deletions(-) (limited to 'completions/jq') diff --git a/completions/jq b/completions/jq index 2d99c39..7021d2a 100644 --- a/completions/jq +++ b/completions/jq @@ -1,24 +1,26 @@ # jq(1) completion -*- shell-script -*- -_jq() +_comp_cmd_jq() { - local cur prev words cword - _init_completion || return + local cur prev words cword comp_args + _comp_initialize -- "$@" || return + local noargopts='!(-*|*[fL]*)' + # shellcheck disable=SC2254 case $prev in --help | --version | --arg | --argjson | --slurpfile | --argfile) return ;; --indent) - COMPREPLY=($(compgen -W '{1..8}' -- "$cur")) + _comp_compgen -- -W '{1..8}' return ;; - --from-file | --run-tests | -!(-*)f) - _filedir + --from-file | --run-tests | -${noargopts}f) + _comp_compgen_filedir return ;; - -!(-*)L) - _filedir -d + -${noargopts}L) + _comp_compgen_filedir -d return ;; esac @@ -29,26 +31,49 @@ _jq() return ;; --slurpfile | --argfile) - _filedir json + _comp_compgen_filedir 'json?(l)' return ;; esac if [[ $cur == -* ]]; then - COMPREPLY=($(compgen -W '$(_parse_help "$1")' -- "$cur")) + # Get jq's --help output and see whether it mentions --help + # jq's --help only shows some of its command-line options; some are not + # even listed in the man page! + local help_output=$("$1" --help 2>/dev/null) + + if [[ $help_output == *--help* ]]; then + # If the output of --help seems complete, use it + _comp_compgen_help - <<<"$help_output" + else + # Otherwise, use a hard-coded list of known flags, some of which do + # not appear in the output of --help as of jq 1.6. + _comp_compgen -- -W '--version --seq --stream --slurp --raw-input + --null-input --compact-output --tab --indent --color-output + -monochrome-output --ascii-output --unbuffered --sort-keys + --raw-output --join-output --from-file --exit-status --arg + --argjson --slurpfile --rawfile --argfile --args --jsonargs + --run-tests --help' + fi return fi - local args + local word + for word in "${words[@]}"; do + [[ $word != --?(json)args ]] || return + done + + local REPLY # TODO: DTRT with args taking 2 options - _count_args "" "@(--arg|--arg?(json|file)|--?(slurp|from-)file|--indent|--run-tests|-!(-*)[fL])" + # -f|--from-file are not counted here because they supply the filter + _comp_count_args -a "@(--arg|--arg?(json|file)|--slurpfile|--indent|--run-tests|-${noargopts}L)" # 1st arg is filter - ((args == 1)) && return + ((REPLY == 1)) && return # 2... are input files - _filedir json + _comp_compgen_filedir 'json?(l)' } && - complete -F _jq jq + complete -F _comp_cmd_jq jq # ex: filetype=sh -- cgit v1.2.3