/bash_completion.d/gcc

http://github.com/brinkman83/bashrc · #! · 59 lines · 53 code · 6 blank · 0 comment · 0 complexity · 647ea38afbaa29b0325d711cde749dc8 MD5 · raw file

  1. # gcc(1) completion
  2. #
  3. # The only unusual feature is that we don't parse "gcc --help -v" output
  4. # directly, because that would include the options of all the other backend
  5. # tools (linker, assembler, preprocessor, etc) without any indication that
  6. # you cannot feed such options to the gcc driver directly. (For example, the
  7. # linker takes a -z option, but you must type -Wl,-z for gcc.) Instead, we
  8. # ask the driver ("g++") for the name of the compiler ("cc1"), and parse the
  9. # --help output of the compiler.
  10. have gcc &&
  11. _gcc()
  12. {
  13. local cur cc backend
  14. COMPREPLY=()
  15. cur=`_get_cword`
  16. _expand || return 0
  17. case "$1" in
  18. gcj)
  19. backend=jc1
  20. ;;
  21. gpc)
  22. backend=gpc1
  23. ;;
  24. *77)
  25. backend=f771
  26. ;;
  27. *)
  28. backend=cc1 # (near-)universal backend
  29. ;;
  30. esac
  31. if [[ "$cur" == -* ]]; then
  32. cc=$( $1 -print-prog-name=$backend )
  33. # sink stderr:
  34. # for C/C++/ObjectiveC it's useless
  35. # for FORTRAN/Java it's an error
  36. COMPREPLY=( $( compgen -W "$( $cc --help 2>/dev/null | \
  37. tr '\t' ' ' | \
  38. sed -e '/^ *-/!d' -e 's/ *-\([^ ]*\).*/-\1/' | \
  39. sort -u )" -- "$cur" ) )
  40. else
  41. _filedir
  42. fi
  43. } &&
  44. complete $filenames -F _gcc gcc g++ c++ g77 gcj gpc
  45. [ $USERLAND = GNU -o $UNAME = Cygwin ] && \
  46. [ -n "${have:-}" ] && complete $filenames -F _gcc cc
  47. # Local variables:
  48. # mode: shell-script
  49. # sh-basic-offset: 4
  50. # sh-indent-comment: t
  51. # indent-tabs-mode: nil
  52. # End:
  53. # ex: ts=4 sw=4 et filetype=sh