# gcc(1) completion -*- shell-script -*- # # The only unusual feature is that we don't parse "gcc --help -v" output # directly, because that would include the options of all the other backend # tools (linker, assembler, preprocessor, etc) without any indication that # you cannot feed such options to the gcc driver directly. (For example, the # linker takes a -z option, but you must type -Wl,-z for gcc.) Instead, we # ask the driver ("g++") for the name of the compiler ("cc1"), and parse the # --help output of the compiler. proc _gcc { var cur = '', prev = '', words = '', cword = '' _init_completion || return _expand || return 0 var cc = '', backend = '' matchstr $1 { gcj { backend := 'jc1' } gpc { backend := 'gpc1' } *77 { backend := 'f771' } *95 { backend := 'f951' } * { backend := 'cc1' # (near-)universal backend } } if [[ "$cur" == -* ]] { cc := $[ $1 -print-prog-name=$backend !2 >/dev/null] [[ $cc ]] || return # sink stderr: # for C/C++/ObjectiveC it's useless # for FORTRAN/Java it's an error global COMPREPLY := '( '$( compgen -W "$( $cc --help 2>/dev/null | tr '\t' ' ' |\ sed -e '/^ *-/!d' -e 's/ *-\([^][ <>]*\).*/-\1/' )" -- "$cur" ) ) [[ $COMPREPLY == *= ]] && compopt -o nospace } else { _filedir } } && complete -F _gcc gcc g++ gfortran g77 g95 gcj gpc && do { cc --version !2 >/dev/null | command grep -q GCC || \ [[ $( _realcommand cc ) == *gcc* ]] && \ complete -F _gcc cc || complete -F _minimal cc c++ --version !2 >/dev/null | command grep -q GCC || \ [[ $( _realcommand c++ ) == *g++* ]] && \ complete -F _gcc c++ || complete -F _minimal c++ f77 --version !2 >/dev/null | command grep -q GCC || \ [[ $( _realcommand f77 ) == *gfortran* ]] && \ complete -F _gcc f77 || complete -F _minimal f77 f95 --version !2 >/dev/null | command grep -q GCC || \ [[ $( _realcommand f95 ) == *gfortran* ]] && \ complete -F _gcc f95 || complete -F _minimal f95 } # ex: ts=4 sw=4 et filetype=sh (CommandList children: [ (AndOr children: [ (FuncDef name: _gcc body: (BraceGroup children: [ (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs:(LhsName name:cur) op:Equal spids:[37]) (assign_pair lhs:(LhsName name:prev) op:Equal spids:[39]) (assign_pair lhs:(LhsName name:words) op:Equal spids:[41]) (assign_pair lhs:(LhsName name:cword) op:Equal spids:[43]) ] spids: [35] ) (AndOr children: [(C {(_init_completion)}) (ControlFlow token:)] op_id: Op_DPipe ) (AndOr children: [ (C {(_expand)}) (ControlFlow token: arg_word:{(0)}) ] op_id: Op_DPipe ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs:(LhsName name:cc) op:Equal spids:[66]) (assign_pair lhs:(LhsName name:backend) op:Equal spids:[68]) ] spids: [64] ) (Case to_match: {($ VSub_Number "$1")} arms: [ (case_arm pat_list: [{(gcj)}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:backend) op: Equal rhs: {(jc1)} spids: [83] ) ] spids: [83] ) ] spids: [79 80 87 -1] ) (case_arm pat_list: [{(gpc)}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:backend) op: Equal rhs: {(gpc1)} spids: [94] ) ] spids: [94] ) ] spids: [90 91 98 -1] ) (case_arm pat_list: [{(Lit_Other "*") (77)}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:backend) op: Equal rhs: {(f771)} spids: [106] ) ] spids: [106] ) ] spids: [101 103 110 -1] ) (case_arm pat_list: [{(Lit_Other "*") (95)}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:backend) op: Equal rhs: {(f951)} spids: [118] ) ] spids: [118] ) ] spids: [113 115 122 -1] ) (case_arm pat_list: [{(Lit_Other "*")}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:backend) op: Equal rhs: {(cc1)} spids: [129] ) ] spids: [129] ) ] spids: [125 126 136 -1] ) ] spids: [72 76 139] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(DQ ($ VSub_Name "$cur"))} right: {(-) (Lit_Other "*")} ) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:cc) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (SimpleCommand words: [ {($ VSub_Number "$1")} {(-print-prog-name) (Lit_Other "=") ($ VSub_Name "$backend") } ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [171] ) ] ) ] ) left_token: spids: [163 174] ) } spids: [162] ) ] spids: [162] ) (AndOr children: [ (DBracket expr: (WordTest w:{($ VSub_Name "$cc")}) ) (ControlFlow token: ) ] op_id: Op_DPipe ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:COMPREPLY) op: Equal rhs: { (ArrayLiteralPart words: [ { (CommandSubPart command_list: (CommandList children: [ (C {(compgen)} {(-W)} { (DQ (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (SimpleCommand words: [ {($ VSub_Name "$cc")} {(--help)} ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [216] ) ] ) (C {(tr)} {(SQ <"\\t">)} {(SQ <" ">)}) (C {(sed)} {(-e)} {(SQ <"/^ *-/!d">)} {(-e)} {(SQ <"s/ *-\\([^][ <>]*\\).*/-\\1/">)} ) ] negated: False ) ] ) left_token: spids: [210 248] ) ) } {(--)} {(DQ ($ VSub_Name "$cur"))} ) ] ) left_token: spids: [203 257] ) } ] ) } spids: [200] ) ] spids: [200] ) (AndOr children: [ (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Name "$COMPREPLY")} right: {(Lit_Other "*") (BoolBinary_GlobEqual "=")} ) ) (C {(compopt)} {(-o)} {(nospace)}) ] op_id: Op_DAmp ) ] spids: [-1 159] ) ] else_action: [(C {(_filedir)})] spids: [282 288] ) ] spids: [32] ) spids: [28 31] ) (AndOr children: [ (C {(complete)} {(-F)} {(_gcc)} {(gcc)} {(g) (Lit_Other "+") (Lit_Other "+")} {(gfortran)} {(g77)} {(g95)} {(gcj)} {(gpc)} ) (BraceGroup children: [ (AndOr children: [ (Pipeline children: [ (SimpleCommand words: [{(cc)} {(--version)}] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [325] ) ] ) (C {(command)} {(grep)} {(-q)} {(GCC)}) ] negated: False ) (AndOr children: [ (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: { (CommandSubPart command_list: (CommandList children: [(C {(_realcommand)} {(cc)})] ) left_token: spids: [344 350] ) } right: {(Lit_Other "*") (gcc) (Lit_Other "*")} ) ) (AndOr children: [ (C {(complete)} {(-F)} {(_gcc)} {(cc)}) (C {(complete)} {(-F)} {(_minimal)} {(cc)}) ] op_id: Op_DPipe ) ] op_id: Op_DAmp ) ] op_id: Op_DPipe ) (AndOr children: [ (Pipeline children: [ (SimpleCommand words: [{(c) (Lit_Other "+") (Lit_Other "+")} {(--version)}] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [389] ) ] ) (C {(command)} {(grep)} {(-q)} {(GCC)}) ] negated: False ) (AndOr children: [ (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: { (CommandSubPart command_list: (CommandList children: [ (C {(_realcommand)} {(c) (Lit_Other "+") (Lit_Other "+")}) ] ) left_token: spids: [408 416] ) } right: {(Lit_Other "*") (g) (Lit_Other "+") (Lit_Other "+") (Lit_Other "*")} ) ) (AndOr children: [ (C {(complete)} {(-F)} {(_gcc)} {(c) (Lit_Other "+") (Lit_Other "+")}) (C {(complete)} {(-F)} {(_minimal)} {(c) (Lit_Other "+") (Lit_Other "+")}) ] op_id: Op_DPipe ) ] op_id: Op_DAmp ) ] op_id: Op_DPipe ) (AndOr children: [ (Pipeline children: [ (SimpleCommand words: [{(f77)} {(--version)}] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [459] ) ] ) (C {(command)} {(grep)} {(-q)} {(GCC)}) ] negated: False ) (AndOr children: [ (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: { (CommandSubPart command_list: (CommandList children: [(C {(_realcommand)} {(f77)})] ) left_token: spids: [478 484] ) } right: {(Lit_Other "*") (gfortran) (Lit_Other "*")} ) ) (AndOr children: [ (C {(complete)} {(-F)} {(_gcc)} {(f77)}) (C {(complete)} {(-F)} {(_minimal)} {(f77)}) ] op_id: Op_DPipe ) ] op_id: Op_DAmp ) ] op_id: Op_DPipe ) (AndOr children: [ (Pipeline children: [ (SimpleCommand words: [{(f95)} {(--version)}] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [521] ) ] ) (C {(command)} {(grep)} {(-q)} {(GCC)}) ] negated: False ) (AndOr children: [ (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: { (CommandSubPart command_list: (CommandList children: [(C {(_realcommand)} {(f95)})] ) left_token: spids: [540 546] ) } right: {(Lit_Other "*") (gfortran) (Lit_Other "*")} ) ) (AndOr children: [ (C {(complete)} {(-F)} {(_gcc)} {(f95)}) (C {(complete)} {(-F)} {(_minimal)} {(f95)}) ] op_id: Op_DPipe ) ] op_id: Op_DAmp ) ] op_id: Op_DPipe ) ] spids: [318] ) ] op_id: Op_DAmp ) ] op_id: Op_DAmp ) ] )