diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 01:03:19 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 01:03:19 +0000 |
commit | 6c09f2a45c5541e9c207d14fc7aa21a4a0066bde (patch) | |
tree | 0221189d367bf661f6f9493c4f17a03f0dd4b7d2 /completions/man | |
parent | Releasing progress-linux version 1:2.11-8~progress7.99u1. (diff) | |
download | bash-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/man')
-rw-r--r-- | completions/man | 103 |
1 files changed, 56 insertions, 47 deletions
diff --git a/completions/man b/completions/man index 81d06f5..b405f08 100644 --- a/completions/man +++ b/completions/man @@ -1,86 +1,95 @@ # man(1) completion -*- shell-script -*- -_man() +_comp_cmd_man() { - local cur prev words cword split - _init_completion -s -n : || return + local cur prev words cword was_split comp_args + _comp_initialize -s -n : -- "$@" || return - local comprsuffix=".@([glx]z|bz2|lzma|Z)" - local manext="@([0-9lnp]|[0-9][px]|man|3?(gl|pm))?($comprsuffix)" - local mansect="@([0-9lnp]|[0-9][px]|3?(gl|pm))" + local comprsuffix=".@([glx]z|bz2|lzma|Z|zst)" + local manext="@([0-9]*([a-z])|[lnp]|man)?($comprsuffix)" + local mansect="@([0-9]*([a-z])|[lnp])" + local noargopts='!(-*|*[ClMSsPpLmerRE]*)' + # shellcheck disable=SC2254 case $prev in - --config-file | -!(-*)C) - _filedir conf + --config-file | -${noargopts}C) + _comp_compgen_filedir conf return ;; - --local-file | -!(-*)l) - _filedir "$manext" + --local-file | -${noargopts}l) + _comp_compgen_filedir "$manext" return ;; - --manpath | -!(-*)M) - _filedir -d + --manpath | -${noargopts}M) + _comp_compgen_filedir -d return ;; - --pager | -!(-*)P) - compopt -o filenames - COMPREPLY=($(compgen -c -- "$cur")) + --sections | -${noargopts}[Ss]) + _comp_delimited : -W '{1..9}' return ;; - --preprocessor | -!(-*)p) - COMPREPLY=($(compgen -W 'e p t g r v' -- "$cur")) + --pager | -${noargopts}P) + _comp_compgen_commands + return + ;; + --preprocessor | -${noargopts}p) + _comp_compgen -- -W 'e p t g r v' return ;; --locale | --systems | --extension | --prompt | --recode | --encoding | \ - -!(-*)[LmerRE]) + -${noargopts}[LmerRE]) return ;; esac - $split && return + [[ $was_split ]] && return if [[ $cur == -* ]]; then - local opts=$(_parse_help "$1" -h) - COMPREPLY=($(compgen -W '${opts:-$(_parse_usage "$1")}' -- "$cur")) + _comp_compgen_help -- -h || _comp_compgen_usage [[ ${COMPREPLY-} == *= ]] && compopt -o nospace return fi # file based completion if parameter looks like a path - if [[ $cur == @(*/|[.~])* ]]; then - _filedir "$manext" + if _comp_looks_like_path "$cur"; then + _comp_compgen_filedir "$manext" return fi local manpath=$(manpath 2>/dev/null || command man -w 2>/dev/null) - [[ -z $manpath ]] && manpath="/usr/share/man:/usr/local/share/man" + if [[ ! $manpath ]]; then + # Note: Both "manpath" and "man -w" may be unavailable, in + # which case we determine the man paths based on the + # environment variable MANPATH. + manpath=:${MANPATH-}: + # Note: An empty path (represented by two consecutive colons + # or a preceding/trailing colon) represents the system man + # paths. + manpath=${manpath//::/':/usr/share/man:/usr/local/share/man:'} + manpath=${manpath:1:-1} + fi # determine manual section to search local sect # shellcheck disable=SC2053 [[ $prev == $mansect ]] && sect=$prev || sect='*' - _expand || return - - manpath=$manpath: - if [[ -n $cur ]]; then - manpath="${manpath//://*man$sect/$cur* } ${manpath//://*cat$sect/$cur* }" - else - manpath="${manpath//://*man$sect/ } ${manpath//://*cat$sect/ }" - fi - - local IFS=$' \t\n' reset=$(shopt -p failglob) - shopt -u failglob - # redirect stderr for when path doesn't exist - COMPREPLY=($(eval command ls "$manpath" 2>/dev/null)) - $reset + _comp_split -F : manpath "$manpath" + if ((${#manpath[@]})); then + local manfiles + _comp_compgen -Rv manfiles -- -S "/*man$sect/$cur*" -W '"${manpath[@]}"' + _comp_compgen -aRv manfiles -- -S "/*cat$sect/$cur*" -W '"${manpath[@]}"' - if ((${#COMPREPLY[@]} != 0)); then - # weed out directory path names and paths to man pages - COMPREPLY=(${COMPREPLY[@]##*/?(:)}) - # strip suffix from man pages - COMPREPLY=(${COMPREPLY[@]%$comprsuffix}) - COMPREPLY=($(compgen -W '${COMPREPLY[@]%.*}' -- "${cur//\\\\/}")) + local IFS= + if _comp_expand_glob COMPREPLY '${manfiles[@]}'; then + # weed out directory path names and paths to man pages (empty + # elements will be removed by the later `compgen -X ''`) + COMPREPLY=("${COMPREPLY[@]##*/?(:)}") + # strip suffix from man pages + COMPREPLY=("${COMPREPLY[@]%$comprsuffix}") + _comp_compgen -c "${cur//\\\\/}" -- -W '"${COMPREPLY[@]%.*}"' -X '' + fi + _comp_unlocal IFS fi # shellcheck disable=SC2053 @@ -88,14 +97,14 @@ _man() # File based completion for the rest, prepending ./ if needed # (man 1.6f needs that for man pages in current dir) local i start=${#COMPREPLY[@]} - _filedir "$manext" + _comp_compgen -a filedir "$manext" for ((i = start; i < ${#COMPREPLY[@]}; i++)); do [[ ${COMPREPLY[i]} == */* ]] || COMPREPLY[i]=./${COMPREPLY[i]} done fi - __ltrim_colon_completions "$cur" + _comp_ltrim_colon_completions "$cur" } && - complete -F _man man apropos whatis + complete -F _comp_cmd_man man apropos whatis # ex: filetype=sh |