summaryrefslogtreecommitdiffstats
path: root/completions/jq
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 01:03:18 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 01:03:18 +0000
commitf4acb49ea148cdd899f7f29f1591c7bc853c2135 (patch)
treeb62d60873864065d6428a84a119dd8a3c90f1397 /completions/jq
parentAdding upstream version 1:2.11. (diff)
downloadbash-completion-f4acb49ea148cdd899f7f29f1591c7bc853c2135.tar.xz
bash-completion-f4acb49ea148cdd899f7f29f1591c7bc853c2135.zip
Adding upstream version 1:2.12.0.upstream/1%2.12.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'completions/jq')
-rw-r--r--completions/jq55
1 files changed, 40 insertions, 15 deletions
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