_man(): use manpath instead of /etc/man{,path}.config to find list of paths
to search. This approach honours $MANPATH _man(): fixed bug that caused a spurious ':' to be returned as a possible completion for all manual sections
This commit is contained in:
parent
d9f457cf96
commit
fe26df90fd
@ -1,6 +1,6 @@
|
|||||||
# bash_completion - some programmable completion functions for bash 2.05a
|
# bash_completion - some programmable completion functions for bash 2.05a
|
||||||
#
|
#
|
||||||
# $Id: bash_completion,v 1.115 2002/02/14 21:11:31 ianmacd Exp $
|
# $Id: bash_completion,v 1.116 2002/02/14 23:39:04 ianmacd Exp $
|
||||||
#
|
#
|
||||||
# Copyright (C) Ian Macdonald <ian@caliban.org>
|
# Copyright (C) Ian Macdonald <ian@caliban.org>
|
||||||
#
|
#
|
||||||
@ -283,7 +283,7 @@ _insmod()
|
|||||||
[ $OS = Linux ] &&
|
[ $OS = Linux ] &&
|
||||||
_man()
|
_man()
|
||||||
{
|
{
|
||||||
local cur prev cmd sect config i
|
local cur prev sect i manpath
|
||||||
|
|
||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
cur=${COMP_WORDS[COMP_CWORD]}
|
cur=${COMP_WORDS[COMP_CWORD]}
|
||||||
@ -293,28 +293,27 @@ _man()
|
|||||||
|
|
||||||
# default completion if parameter contains /
|
# default completion if parameter contains /
|
||||||
[[ "$cur" == */* ]] && return 0
|
[[ "$cur" == */* ]] && return 0
|
||||||
# default to command completion if no man config file
|
|
||||||
for i in /etc/man{,path}.config; do
|
manpath=$( manpath )
|
||||||
[ -r $i ] && config=$i
|
if [ -z "$manpath" ]; then
|
||||||
done
|
|
||||||
if [ -z "$config" ]; then
|
|
||||||
COMPREPLY=( $( compgen -c $cur ) )
|
COMPREPLY=( $( compgen -c $cur ) )
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# determine manual section to search
|
# determine manual section to search
|
||||||
[[ "$prev" == [0-9ln] ]] && sect=$prev || sect='?'
|
[[ "$prev" == [0-9ln] ]] && sect=$prev || sect='?'
|
||||||
|
|
||||||
|
manpath=$manpath:
|
||||||
|
if [ -n "$cur" ]; then
|
||||||
|
manpath="${manpath//://man$sect/$cur* }"
|
||||||
|
else
|
||||||
|
manpath="${manpath//://man$sect/ }"
|
||||||
|
fi
|
||||||
|
|
||||||
# churn out a string of paths to search, with * appended to $cur
|
|
||||||
cmd=`awk '{if ($1 ~ /^MANPATH/) print $(NF)"/man'$sect'/'$cur'*"}' \
|
|
||||||
/etc/man.config | sort -u`
|
|
||||||
# strip off * from paths ending in /*
|
|
||||||
cmd=${cmd//\/\\*/\/}
|
|
||||||
# redirect stderr for when path doesn't exist
|
# redirect stderr for when path doesn't exist
|
||||||
cmd="ls $cmd 2>/dev/null"
|
COMPREPLY=( $( eval ls $manpath 2>/dev/null ) )
|
||||||
COMPREPLY=( $( eval $cmd ) )
|
# weed out directory path names and paths to man pages
|
||||||
# get basename of man pages
|
COMPREPLY=( ${COMPREPLY[@]##*/?(:)} )
|
||||||
COMPREPLY=( ${COMPREPLY[@]##*/} )
|
|
||||||
# strip suffix from man pages
|
# strip suffix from man pages
|
||||||
COMPREPLY=( ${COMPREPLY[@]%.@(gz|bz2)} )
|
COMPREPLY=( ${COMPREPLY[@]%.@(gz|bz2)} )
|
||||||
COMPREPLY=( ${COMPREPLY[@]%.*} )
|
COMPREPLY=( ${COMPREPLY[@]%.*} )
|
||||||
|
Loading…
x
Reference in New Issue
Block a user