summaryrefslogtreecommitdiff
path: root/completions/man
diff options
context:
space:
mode:
Diffstat (limited to 'completions/man')
-rw-r--r--completions/man18
1 files changed, 10 insertions, 8 deletions
diff --git a/completions/man b/completions/man
index 0c3769d5..6e42f85f 100644
--- a/completions/man
+++ b/completions/man
@@ -8,10 +8,9 @@ _man()
local cur prev words cword split
_init_completion -s -n : || return
- local sect manpath manext mansect
-
- manext="@([0-9lnp]|[0-9][px]|man|3?(gl|pm))?(.@([gx]z|bz2|lzma|Z))"
- mansect="@([0-9lnp]|[0-9][px]|3?(gl|pm))"
+ 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))"
case $prev in
-C|--config-file)
@@ -19,7 +18,7 @@ _man()
return
;;
-l|--local-file)
- _filedir $manext
+ _filedir "$manext"
return
;;
-M|--manpath)
@@ -27,6 +26,7 @@ _man()
return
;;
-P|--pager)
+ compopt -o filenames
COMPREPLY=( $( compgen -c -- "$cur" ) )
return
;;
@@ -52,10 +52,11 @@ _man()
# file based completion if parameter looks like a path
if [[ "$cur" == @(*/|[.~])* ]]; then
- _filedir $manext
+ _filedir "$manext"
return 0
fi
+ local manpath
if [[ $OSTYPE == *@(darwin|linux|freebsd|cygwin)* ]] || _userland GNU; then
manpath=$( manpath 2>/dev/null || command man --path )
else
@@ -68,6 +69,7 @@ _man()
fi
# determine manual section to search
+ local sect
[[ "$prev" == $mansect ]] && sect=$prev || sect='*'
manpath=$manpath:
@@ -82,14 +84,14 @@ _man()
# weed out directory path names and paths to man pages
COMPREPLY=( ${COMPREPLY[@]##*/?(:)} )
# strip suffix from man pages
- COMPREPLY=( ${COMPREPLY[@]%.@([gx]z|bz2|lzma|Z)} )
+ COMPREPLY=( ${COMPREPLY[@]%$comprsuffix} )
COMPREPLY=( $( compgen -W '${COMPREPLY[@]%.*}' -- "${cur//\\\\/}" ) )
if [[ "$prev" != $mansect ]]; then
# 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
+ _filedir "$manext"
for (( i=$start; i < ${#COMPREPLY[@]}; i++ )); do
[[ ${COMPREPLY[i]} == */* ]] || COMPREPLY[i]=./${COMPREPLY[i]}
done