Support "man cmd subcmd" completion in contrib/man (Debian: #545411)
This commit is contained in:
parent
046f2abc6f
commit
584bc520df
1
CHANGES
1
CHANGES
@ -36,6 +36,7 @@ bash-completion (1.x)
|
|||||||
* Improve qemu completion (Debian: #534901)
|
* Improve qemu completion (Debian: #534901)
|
||||||
* Added sshfs completion (shares the same as scp) (Debian: #545978)
|
* Added sshfs completion (shares the same as scp) (Debian: #545978)
|
||||||
* Fixed obvious brokenness (typos) in contrib/mdadm
|
* Fixed obvious brokenness (typos) in contrib/mdadm
|
||||||
|
* Support "man cmd subcmd" completion in contrib/man (Debian: #545411)
|
||||||
|
|
||||||
[ Ville Skyttä ]
|
[ Ville Skyttä ]
|
||||||
* Split yum completion to contrib/_yum (no longer installed by default, the
|
* Split yum completion to contrib/_yum (no longer installed by default, the
|
||||||
|
16
contrib/man
16
contrib/man
@ -8,7 +8,7 @@
|
|||||||
-o $UNAME = OpenBSD ] &&
|
-o $UNAME = OpenBSD ] &&
|
||||||
_man()
|
_man()
|
||||||
{
|
{
|
||||||
local cur i prev sect manpath manext mansect uname
|
local cur i prev sect manpath manext mansect uname version subcommands
|
||||||
|
|
||||||
manext="@([0-9lnp]|[0-9][px]|man|3pm)?(.@(gz|bz2|lzma))"
|
manext="@([0-9lnp]|[0-9][px]|man|3pm)?(.@(gz|bz2|lzma))"
|
||||||
mansect="@([0-9lnp]|[0-9][px]|3pm)"
|
mansect="@([0-9lnp]|[0-9][px]|3pm)"
|
||||||
@ -16,6 +16,7 @@ _man()
|
|||||||
COMPREPLY=()
|
COMPREPLY=()
|
||||||
cur=`_get_cword`
|
cur=`_get_cword`
|
||||||
prev=${COMP_WORDS[COMP_CWORD-1]}
|
prev=${COMP_WORDS[COMP_CWORD-1]}
|
||||||
|
version=$(man --version | cut -d\ -f2)
|
||||||
|
|
||||||
if [[ "$prev" == -l ]]; then
|
if [[ "$prev" == -l ]]; then
|
||||||
_filedir $manext
|
_filedir $manext
|
||||||
@ -52,6 +53,19 @@ _man()
|
|||||||
manpath="${manpath//://*man$sect/ } ${manpath//://*cat$sect/ }"
|
manpath="${manpath//://*man$sect/ } ${manpath//://*cat$sect/ }"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Check whether $prev has "subcommand" manpages -- not always right! (try man hg ssh, then $ hg ssh)
|
||||||
|
# Unfortunately, there's no way to check whether a completion is a valid subcommand or not.
|
||||||
|
# man cmd subcmd is only supported from man-db 2.5.6
|
||||||
|
if ([ ${version:0:1} -eq 2 ] && [ ${version:2:1} -eq 5 ] && [ ${version:4:1} -gt 5 ]) ||
|
||||||
|
([ ${version:0:1} -eq 2 ] && [ ${version:2:1} -gt 5 ]) ||
|
||||||
|
[ ${version:0:1} -gt 2 ]; then
|
||||||
|
subcommands=$(whatis -w "$prev-*" | awk '{print $1}' | sed -e "s/$prev-//g" | tr "\n" " ")
|
||||||
|
if [ -n "$subcommands" ]; then
|
||||||
|
COMPREPLY=( $( compgen -W "$subcommands" -- $cur ) )
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# redirect stderr for when path doesn't exist
|
# redirect stderr for when path doesn't exist
|
||||||
COMPREPLY=( $( eval command ls "$manpath" 2>/dev/null ) )
|
COMPREPLY=( $( eval command ls "$manpath" 2>/dev/null ) )
|
||||||
# weed out directory path names and paths to man pages
|
# weed out directory path names and paths to man pages
|
||||||
|
Loading…
x
Reference in New Issue
Block a user