/bash_completion.d/m-a

http://github.com/brinkman83/bashrc · #! · 78 lines · 62 code · 16 blank · 0 comment · 0 complexity · 024cf1aaa1287981f5d339345cfcf65a MD5 · raw file

  1. #-*- mode: shell-script;-*-
  2. # Inputs:
  3. # $1 -- name of the command whose arguments are being completed
  4. # $2 -- word being completed
  5. # $3 -- word preceding the word being completed
  6. # $COMP_LINE -- current command line
  7. # $COMP_PONT -- cursor position
  8. # $COMP_WORDS -- array containing individual words in the current
  9. # command line
  10. # $COMP_CWORD -- index into ${COMP_WORDS} of the word containing the
  11. # current cursor position
  12. # Output:
  13. # COMPREPLY array variable contains possible completions
  14. #
  15. # Syntax (simple:
  16. # module-assistant [options] command module [module ...]
  17. have module-assistant &&
  18. _module_assistant() {
  19. local cur prev special i options commands
  20. options='-h -v -q -n -i -o -s -f -u -k -l \
  21. --help --verbose --quiet --no-rebuild --non-inter --unpack-once \
  22. --apt-search --force --userdir --kernel-dir --kvers-list'
  23. commands='update unpack get fakesource build list install auto-install prepare clean purge la li a-i'
  24. COMPREPLY=()
  25. cur=${COMP_WORDS[COMP_CWORD]}
  26. prev=${COMP_WORDS[COMP_CWORD-1]}
  27. for (( i=0; i < ${#COMP_WORDS[@]}-1; i++ )); do
  28. if [[ ${COMP_WORDS[i]} == @(update|fakesource|unpack|get|build|list|install|auto-install|clean|purge|la|list-available|li|list-installed|a-i) ]]; then
  29. special=${COMP_WORDS[i]}
  30. fi
  31. done
  32. if [ -n "$special" ]; then
  33. case $special in
  34. clean|purge)
  35. COMPREPLY=( $( module-assistant -q compi $cur 2> /dev/null ) )
  36. return 0
  37. ;;
  38. *)
  39. COMPREPLY=( $( module-assistant -q comp $cur 2> /dev/null ) )
  40. return 0
  41. ;;
  42. esac
  43. fi
  44. case "$prev" in
  45. -@(u|k|-kernel-dir|-kernel-dirs))
  46. _filedir
  47. return 0
  48. ;;
  49. -@(l|-kver-list))
  50. COMPREPLY=( $( module-assistant -q compv $cur ) )
  51. return 0
  52. ;;
  53. esac
  54. if [[ "$cur" == -* ]]; then
  55. COMPREPLY=( $( compgen -W "$options" -- $cur ) )
  56. else
  57. COMPREPLY=( $( compgen -W "$commands" -- $cur ) )
  58. fi
  59. return 0
  60. }
  61. [ "$have" ] && complete -F _module_assistant $filenames module-assistant
  62. [ "$have" ] && complete -F _module_assistant $filenames m-a