# bash completion for wvdial -*- shell-script -*- proc _wvdial { var cur = '', prev = '', words = '', cword = '', split = '' _init_completion -s || return matchstr $prev { --config { _filedir return 0 } } $split && return var config = '', i = '', IFS = '$'\n'' matchstr $cur { -* { global COMPREPLY := '( '$( compgen -W '$( _parse_help "$1" )' -- "$cur" ) ) [[ $COMPREPLY == *= ]] && compopt -o nospace } * { # start with global and personal config files config := ""/etc/wvdial.conf"$'\n'"$HOME/.wvdialrc"" # replace with command line config file if present for (( i=1; i < cword; i++ )); do if [[ "${words[i]}" == "--config" ]]; then config=${words[i+1]} break fi done # parse config files for sections and # remove default section global COMPREPLY := '( '$( sed -ne "s|^\[Dialer \($cur.*\)\]$|\1|p" $config \ 2>/dev/null | command grep -v '^Defaults$')) # escape spaces global COMPREPLY := $(COMPREPLY// /\\ ) } } } && complete -F _wvdial wvdial # ex: ts=4 sw=4 et filetype=sh (CommandList children: [ (AndOr children: [ (FuncDef name: _wvdial body: (BraceGroup children: [ (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs:(LhsName name:cur) op:Equal spids:[13]) (assign_pair lhs:(LhsName name:prev) op:Equal spids:[15]) (assign_pair lhs:(LhsName name:words) op:Equal spids:[17]) (assign_pair lhs:(LhsName name:cword) op:Equal spids:[19]) (assign_pair lhs:(LhsName name:split) op:Equal spids:[21]) ] spids: [11] ) (AndOr children: [ (C {(_init_completion)} {(-s)}) (ControlFlow token:) ] op_id: Op_DPipe ) (Case to_match: {($ VSub_Name "$prev")} arms: [ (case_arm pat_list: [{(--config)}] action: [ (C {(_filedir)}) (ControlFlow token: arg_word: {(0)} ) ] spids: [41 42 53 -1] ) ] spids: [34 38 56] ) (AndOr children: [ (C {($ VSub_Name "$split")}) (ControlFlow token:) ] op_id: Op_DAmp ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs:(LhsName name:config) op:Equal spids:[70]) (assign_pair lhs:(LhsName name:i) op:Equal spids:[72]) (assign_pair lhs: (LhsName name:IFS) op: Equal rhs: {(SQ )} spids: [74] ) ] spids: [68] ) (Case to_match: {($ VSub_Name "$cur")} arms: [ (case_arm pat_list: [{(-) (Lit_Other "*")}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:COMPREPLY) op: Equal rhs: { (ArrayLiteralPart words: [ { (CommandSubPart command_list: (CommandList children: [ (C {(compgen)} {(-W)} {(SQ <"$( _parse_help \"$1\" )">)} {(--)} {(DQ ($ VSub_Name "$cur"))} ) ] ) left_token: spids: [96 112] ) } ] ) } spids: [93] ) ] spids: [93] ) (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: [88 90 137 -1] ) (case_arm pat_list: [{(Lit_Other "*")}] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:config) op: Equal rhs: {(DQ (/etc/wvdial.conf)) (SQ ) (DQ ($ VSub_Name "$HOME") (/.wvdialrc)) } spids: [148] ) ] spids: [148] ) (ForExpr init: (BinaryAssign op_id: Arith_Equal left: (LhsName name:i) right: (ArithWord w:{(Lit_Digits 1)}) ) cond: (ArithBinary op_id: Arith_Less left: (ArithVarRef name:i) right: (ArithVarRef name:cword) ) update: (UnaryAssign op_id:Node_PostDPlus child:(LhsName name:i)) body: (DoGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: { (DQ (BracedVarSub token: bracket_op: (ArrayIndex expr: (ArithVarRef name:i) ) spids: [196 201] ) ) } right: {(DQ (--config))} ) ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:config) op: Equal rhs: { (BracedVarSub token: bracket_op: (ArrayIndex expr: (ArithBinary op_id: Arith_Plus left: (ArithVarRef name:i) right: (ArithWord w:{(Lit_Digits 1)}) ) ) spids: [217 224] ) } spids: [216] ) ] spids: [216] ) (ControlFlow token: ) ] spids: [-1 213] ) ] spids: [-1 230] ) ] spids: [188 233] ) ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:COMPREPLY) op: Equal rhs: { (ArrayLiteralPart words: [ { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (SimpleCommand words: [ {(sed)} {(-ne)} { (DQ ("s|^") (EscapedLiteralPart token: ) ("Dialer ") (EscapedLiteralPart token:) ($ VSub_Name "$cur") (".*") (EscapedLiteralPart token: ) (EscapedLiteralPart token:) (Lit_Other "$") ("|") (EscapedLiteralPart token: ) ("|p") ) } {($ VSub_Name "$config")} ] redirects: [ (Redir op_id: Redir_Great fd: 2 arg_word: {(/dev/null)} spids: [272] ) ] ) (C {(command)} {(grep)} {(-v)} {(SQ <"^Defaults$">)}) ] negated: False ) ] ) left_token: spids: [247 286] ) } ] ) } spids: [244] ) ] spids: [244] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:COMPREPLY) op: Equal rhs: { (BracedVarSub token: suffix_op: (PatSub pat: {(" ")} replace: {(EscapedLiteralPart token:) (" ")} do_all: True do_prefix: False do_suffix: False ) spids: [295 303] ) } spids: [294] ) ] spids: [294] ) ] spids: [140 141 306 -1] ) ] spids: [81 85 309] ) ] spids: [8] ) spids: [4 7] ) (C {(complete)} {(-F)} {(_wvdial)} {(wvdial)}) ] op_id: Op_DAmp ) ] )