/bash_completion_lib/complete -o filenames/info

http://github.com/brinkman83/bashrc · #! · 52 lines · 40 code · 12 blank · 0 comment · 0 complexity · 20c2391e071ae4638f3feb5db7552957 MD5 · raw file

  1. # info(1) completion
  2. comp_include _expand _filedir _get_cword
  3. _info()
  4. {
  5. local cur infopath UNAME
  6. COMPREPLY=()
  7. cur=`_get_cword`
  8. _expand || return 0
  9. # default completion if parameter contains /
  10. if [[ "$cur" == */* ]]; then
  11. _filedir
  12. return 0
  13. fi
  14. infopath='/usr/share/info'
  15. if [ "${INFOPATH: -1:1}" == ':' ]; then
  16. infopath=${INFOPATH}${infopath}
  17. elif [ ${INFOPATH:+set} ]; then
  18. infopath=$INFOPATH
  19. fi
  20. infopath=$infopath:
  21. if [ -n "$cur" ]; then
  22. infopath="${infopath//://$cur* }"
  23. else
  24. infopath="${infopath//:// }"
  25. fi
  26. # redirect stderr for when path doesn't exist
  27. COMPREPLY=( $( eval command ls "$infopath" 2>/dev/null ) )
  28. # weed out directory path names and paths to info pages
  29. COMPREPLY=( ${COMPREPLY[@]##*/?(:)} )
  30. # weed out info dir file
  31. for (( i=0 ; i < ${#COMPREPLY[@]} ; ++i )); do
  32. if [ "${COMPREPLY[$i]}" == 'dir' ]; then
  33. unset COMPREPLY[$i];
  34. fi;
  35. done
  36. # strip suffix from info pages
  37. COMPREPLY=( ${COMPREPLY[@]%.@(gz|bz2)} )
  38. COMPREPLY=( $( compgen -W '${COMPREPLY[@]%.*}' -- "${cur//\\\\/}" ) )
  39. return 0
  40. } # _info()