summaryrefslogtreecommitdiffstats
path: root/completions/jq
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 01:03:19 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 01:03:19 +0000
commit6c09f2a45c5541e9c207d14fc7aa21a4a0066bde (patch)
tree0221189d367bf661f6f9493c4f17a03f0dd4b7d2 /completions/jq
parentReleasing progress-linux version 1:2.11-8~progress7.99u1. (diff)
downloadbash-completion-6c09f2a45c5541e9c207d14fc7aa21a4a0066bde.tar.xz
bash-completion-6c09f2a45c5541e9c207d14fc7aa21a4a0066bde.zip
Merging upstream version 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