aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2015-12-22 16:15:24 +1300
committerTom Ryder <tom@sanctum.geek.nz>2015-12-22 16:15:24 +1300
commitf63c8f73cfdfc0c859fba34868eab8fc924c799e (patch)
treecb8392a0913d02517324b6aa349e24e94e4b38b4
parentAvoid calling cat(1) by using builtins (diff)
downloaddotfiles-f63c8f73cfdfc0c859fba34868eab8fc924c799e.tar.gz
dotfiles-f63c8f73cfdfc0c859fba34868eab8fc924c799e.zip
Better section management for man completion
-rw-r--r--bash/bashrc.d/man.bash23
1 files changed, 15 insertions, 8 deletions
diff --git a/bash/bashrc.d/man.bash b/bash/bashrc.d/man.bash
index be3dc830..b88442d1 100644
--- a/bash/bashrc.d/man.bash
+++ b/bash/bashrc.d/man.bash
@@ -8,11 +8,12 @@ _man() {
local word
word=${COMP_WORDS[COMP_CWORD]}
- # If this is the second word, and the previous word was a number, we'll
- # assume that's the section to search
- local section
- if ((COMP_CWORD > 1)) && [[ ${COMP_WORDS[COMP_CWORD-1]} != [^0-9] ]] ; then
- section='man'${COMP_WORDS[COMP_CWORD-1]}
+ # If this is the second word, and the previous word started with a number,
+ # we'll assume that's the section to search
+ local section subdir
+ if ((COMP_CWORD > 1)) && [[ ${COMP_WORDS[COMP_CWORD-1]} == [0-9]* ]] ; then
+ section=${COMP_WORDS[COMP_CWORD-1]}
+ subdir=man${section%%[^0-9]*}
fi
# Read completion results from a subshell and add them to the COMPREPLY
@@ -35,9 +36,15 @@ _man() {
# Iterate through the manual page paths and add every manual page we find
for manpath in "${manpaths[@]}" ; do
[[ $manpath ]] || continue
- for page in "$manpath"/"$section"*/"$word"*.[0-9]* ; do
- pages[${#pages[@]}]=$page
- done
+ if [[ $section ]] ; then
+ for page in "$manpath"/"$subdir"/"$word"*."$section"@(|.[glx]z|.bz2|.lzma|.Z) ; do
+ pages[${#pages[@]}]=$page
+ done
+ else
+ for page in "$manpath"/man[0-9]*/"$word"*.* ; do
+ pages[${#pages[@]}]=$page
+ done
+ fi
done
# Strip paths, .gz suffixes, and finally .<section> suffixes