blob: 0fa17a0da9f7810755f521e653f9712b0d537484 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
# man(1) completion
[[ $USERLAND == GNU || $UNAME == @(Darwin|FreeBSD|SunOS|Cygwin|OpenBSD) ]] &&
_man()
{
local cur prev words cword split
_init_completion -s -n : || return
local i sect manpath manext mansect uname
manext="@([0-9lnp]|[0-9][px]|man|3pm)?(.@([gx]z|bz2|lzma|Z))"
mansect="@([0-9lnp]|[0-9][px]|3pm)"
case $prev in
-C|--config-file)
_filedir conf
return
;;
-l|--local-file)
_filedir $manext
return
;;
-M|--manpath)
_filedir -d
return
;;
-P|--pager)
COMPREPLY=( $( compgen -c -- "$cur" ) )
return
;;
-p|--preprocessor)
COMPREPLY=( $( compgen -W 'e p t g r v' -- "$cur" ) )
return
;;
-L|--locale|-m|--systems|-e|--extension|-r|--prompt|-R|--recode|\
-E|--encoding)
return
;;
esac
$split && return
if [[ $cur == -* ]]; then
COMPREPLY=( $( compgen -W '$( _parse_help "$1" -h )' -- "$cur" ) )
[[ $COMPREPLY == *= ]] && compopt -o nospace
return
fi
_expand || return 0
# file based completion if parameter looks like a path
if [[ "$cur" == @(*/|[.~])* ]]; then
_filedir $manext
return 0
fi
uname=$( uname -s )
if [[ $uname == @(Linux|GNU|GNU/*|FreeBSD|Cygwin|CYGWIN_*) ]]; then
manpath=$( manpath 2>/dev/null || command man --path )
else
manpath=$MANPATH
fi
if [ -z "$manpath" ]; then
COMPREPLY=( $( compgen -c -- "$cur" ) )
return 0
fi
# determine manual section to search
[[ "$prev" == $mansect ]] && sect=$prev || sect='*'
manpath=$manpath:
if [ -n "$cur" ]; then
manpath="${manpath//://*man$sect/$cur* } ${manpath//://*cat$sect/$cur* }"
else
manpath="${manpath//://*man$sect/ } ${manpath//://*cat$sect/ }"
fi
# redirect stderr for when path doesn't exist
COMPREPLY=( $( eval command ls "$manpath" 2>/dev/null ) )
# 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=( $( 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 start=${#COMPREPLY[@]}
_filedir $manext
for (( i=$start; i < ${#COMPREPLY[@]}; i++ )); do
[[ ${COMPREPLY[i]} == */* ]] || COMPREPLY[i]=./${COMPREPLY[i]}
done
fi
__ltrim_colon_completions "$cur"
return 0
} &&
complete -F _man man apropos whatis
# Local variables:
# mode: shell-script
# sh-basic-offset: 4
# sh-indent-comment: t
# indent-tabs-mode: nil
# End:
# ex: ts=4 sw=4 et filetype=sh
|