PageRenderTime 113ms CodeModel.GetById 110ms app.highlight 0ms RepoModel.GetById 1ms app.codeStats 0ms

/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
11have gcc &&
12_gcc()
13{
14    local cur cc backend
15
16    COMPREPLY=()
17    cur=`_get_cword`
18
19    _expand || return 0
20
21    case "$1" in
22        gcj)
23            backend=jc1
24            ;;
25        gpc)
26            backend=gpc1
27            ;;
28        *77)
29            backend=f771
30            ;;
31        *)
32            backend=cc1 # (near-)universal backend
33            ;;
34    esac
35
36    if [[ "$cur" == -* ]]; then
37        cc=$( $1 -print-prog-name=$backend )
38        # sink stderr:
39        # for C/C++/ObjectiveC it's useless
40        # for FORTRAN/Java it's an error
41        COMPREPLY=( $( compgen -W "$( $cc --help 2>/dev/null | \
42           tr '\t' ' ' | \
43           sed -e '/^  *-/!d' -e 's/ *-\([^ ]*\).*/-\1/' | \
44           sort -u )" -- "$cur" ) )
45    else
46        _filedir
47    fi
48} &&
49complete $filenames -F _gcc gcc g++ c++ g77 gcj gpc
50[ $USERLAND = GNU -o $UNAME = Cygwin ] && \
51[ -n "${have:-}" ] && complete $filenames -F _gcc cc
52
53# Local variables:
54# mode: shell-script
55# sh-basic-offset: 4
56# sh-indent-comment: t
57# indent-tabs-mode: nil
58# End:
59# ex: ts=4 sw=4 et filetype=sh