aboutsummaryrefslogtreecommitdiff
path: root/bash/bashrc.d/man.bash
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-07-30 01:17:09 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-07-30 02:09:30 +1200
commit4cbbd121c012b3962f12fdff0f1820c3b8636a44 (patch)
tree00149270df365ed0b7a1b9e9f4922fe7d5a80eb3 /bash/bashrc.d/man.bash
parentChange ca from Bash func to sh script (diff)
downloaddotfiles-4cbbd121c012b3962f12fdff0f1820c3b8636a44.tar.gz
dotfiles-4cbbd121c012b3962f12fdff0f1820c3b8636a44.zip
Move bash completion setup into separate dir
Diffstat (limited to 'bash/bashrc.d/man.bash')
-rw-r--r--bash/bashrc.d/man.bash63
1 files changed, 0 insertions, 63 deletions
diff --git a/bash/bashrc.d/man.bash b/bash/bashrc.d/man.bash
deleted file mode 100644
index f1762a01..00000000
--- a/bash/bashrc.d/man.bash
+++ /dev/null
@@ -1,63 +0,0 @@
-# Autocompletion for man(1)
-_man() {
-
- # Don't even bother if we don't have manpath(1)
- hash manpath || return 1
-
- # Snarf the word
- local word
- word=${COMP_WORDS[COMP_CWORD]}
-
- # 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
- # array individually
- while IFS= read -rd '' page ; do
- COMPREPLY[${#COMPREPLY[@]}]=$page
- done < <(
-
- # Do not return dotfiles, give us extended globbing, and expand empty
- # globs to just nothing
- shopt -u dotglob
- shopt -s extglob nullglob
-
- # Start an array of pages
- declare -a pages
-
- # Break manpath(1) output into an array of paths
- IFS=: read -a manpaths -r < <(manpath 2>/dev/null)
-
- # Iterate through the manual page paths and add every manual page we find
- for manpath in "${manpaths[@]}" ; do
- [[ $manpath ]] || continue
- 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
- pages=("${pages[@]##*/}")
- pages=("${pages[@]%.@([glx]z|bz2|lzma|Z)}")
- pages=("${pages[@]%.[0-9]*}")
-
- # Bail out if we ended up with no pages somehow to prevent us from
- # printing
- ((${#pages[@]})) || exit 1
-
- # Print the pages array to stdout, quoted and null-delimited
- printf '%q\0' "${pages[@]}"
- )
-}
-complete -F _man -o default man