@@ -77,27 +77,21 @@ _man()
7777 # shellcheck disable=SC2053
7878 [[ $prev == $mansect ]] && sect=$prev || sect=' *'
7979
80- manpath=$manpath :
81- if [[ $cur ]]; then
82- manpath=" ${manpath//://* man$sect / $cur * } ${manpath//://* cat$sect / $cur * } "
83- else
84- manpath=" ${manpath//://* man$sect / } ${manpath//://* cat$sect / } "
85- fi
86-
87- local IFS=$' \t\n ' reset=$( shopt -p failglob)
88- shopt -u failglob
89- # redirect stderr for when path doesn't exist
90- COMPREPLY=($( eval command ls " $manpath " 2> /dev/null) )
91- $reset
80+ _comp_split -F : manpath " $manpath "
81+ if (( ${# manpath[@]} )) ; then
82+ manpath=(" ${manpath[@]/%//* man$sect / $cur * } " " ${manpath[@]/%//* cat$sect / $cur * } " )
83+ local IFS=
84+ _comp_expand_glob COMPREPLY ' ${manpath[@]}'
85+ _comp_unlocal IFS
9286
93- if (( ${# COMPREPLY[@]} != 0 )) ; then
94- # weed out directory path names and paths to man pages
95- COMPREPLY=( ${COMPREPLY[@] ##*/ ?( : )} )
96- # strip suffix from man pages
97- (( ${ # COMPREPLY[@]} )) &&
98- COMPREPLY=(${COMPREPLY[@]% $comprsuffix } )
99- (( ${ # COMPREPLY[@]} )) &&
100- COMPREPLY=( $( compgen -W ' "${COMPREPLY[@]%.*}" ' -- " ${cur // \\\\ / } " ) )
87+ if (( ${# COMPREPLY[@]} != 0 )) ; then
88+ # weed out directory path names and paths to man pages (empty
89+ # elements will be removed by the later `compgen -X ''` )
90+ COMPREPLY=( " ${COMPREPLY[@] ##*/ ?( : )} " )
91+ # strip suffix from man pages
92+ COMPREPLY=(" ${COMPREPLY[@]% $comprsuffix } " )
93+ _comp_split -l COMPREPLY " $( compgen -W ' "${ COMPREPLY[@]%.*}" ' -X ' ' -- " ${cur // \\\\ / } " ) "
94+ fi
10195 fi
10296
10397 # shellcheck disable=SC2053
0 commit comments