home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / etc / bash_completion.d / man < prev    next >
Encoding:
Text File  |  2010-11-16  |  2.3 KB  |  83 lines

  1. # man(1) completion
  2.  
  3. [ $USERLAND = GNU -o $UNAME = Darwin \
  4.   -o $UNAME = FreeBSD -o $UNAME = SunOS -o $UNAME = Cygwin \
  5.   -o $UNAME = OpenBSD ] &&
  6. _man()
  7. {
  8.     local cur i prev sect manpath manext mansect uname
  9.  
  10.     manext="@([0-9lnp]|[0-9][px]|man|3pm)?(.@([gx]z|bz2|lzma|Z))"
  11.     mansect="@([0-9lnp]|[0-9][px]|3pm)"
  12.  
  13.     COMPREPLY=()
  14.     _get_comp_words_by_ref cur prev
  15.  
  16.     if [[ "$prev" == -l ]]; then
  17.         _filedir $manext
  18.         return 0
  19.     fi
  20.  
  21.     _expand || return 0
  22.  
  23.     # file based completion if parameter contains /
  24.     if [[ "$cur" == */* ]]; then
  25.         _filedir $manext
  26.         return 0
  27.     fi
  28.  
  29.     uname=$( uname -s )
  30.     if [[ $uname == @(Linux|GNU|GNU/*|FreeBSD|Cygwin|CYGWIN_*) ]]; then
  31.         manpath=$( manpath 2>/dev/null || command man --path )
  32.     else
  33.         manpath=$MANPATH
  34.     fi
  35.  
  36.     if [ -z "$manpath" ]; then
  37.         COMPREPLY=( $( compgen -c -- "$cur" ) )
  38.         return 0
  39.     fi
  40.  
  41.     # determine manual section to search
  42.     [[ "$prev" == $mansect ]] && sect=$prev || sect='*'
  43.  
  44.     manpath=$manpath:
  45.     if [ -n "$cur" ]; then
  46.         manpath="${manpath//://*man$sect/$cur* } ${manpath//://*cat$sect/$cur* }"
  47.     else
  48.         manpath="${manpath//://*man$sect/ } ${manpath//://*cat$sect/ }"
  49.     fi
  50.  
  51.     # redirect stderr for when path doesn't exist
  52.     COMPREPLY=( $( eval command ls "$manpath" 2>/dev/null ) )
  53.     # weed out directory path names and paths to man pages
  54.     COMPREPLY=( ${COMPREPLY[@]##*/?(:)} )
  55.     # strip suffix from man pages
  56.     COMPREPLY=( ${COMPREPLY[@]%.@([gx]z|bz2|lzma|Z)} )
  57.     COMPREPLY=( $( compgen -W '${COMPREPLY[@]%.*}' -- "${cur//\\\\/}" ) )
  58.  
  59.     if [[ "$prev" != $mansect ]]; then
  60.         # File based completion for the rest, prepending ./ if needed
  61.         # (man 1.6f needs that for man pages in current dir)
  62.         local start=${#COMPREPLY[@]}
  63.         _filedir $manext
  64.         for (( i=$start; i < ${#COMPREPLY[@]}; i++ )); do
  65.             [[ ${COMPREPLY[i]} == */* ]] || COMPREPLY[i]=./${COMPREPLY[i]}
  66.         done
  67.     fi
  68.  
  69.     return 0
  70. }
  71. [ $USERLAND = GNU -o $UNAME = Darwin \
  72.   -o $UNAME = FreeBSD -o $UNAME = SunOS -o $UNAME = Cygwin \
  73.   -o $UNAME = OpenBSD ] && \
  74. complete -F _man -o filenames man apropos whatis
  75.  
  76. # Local variables:
  77. # mode: shell-script
  78. # sh-basic-offset: 4
  79. # sh-indent-comment: t
  80. # indent-tabs-mode: nil
  81. # End:
  82. # ex: ts=4 sw=4 et filetype=sh
  83.