# pkgadd completion -*- shell-script -*- # # Copyright 2006 Yann Rouillard proc _pkgadd { var cur = '', prev = '', words = '', cword = '' _init_completion -n : || return # if a device directory was given # we must complete with the package # available in this directory var device = '/var/spool/pkg'; var i = $cword while [[ $((i--)) -gt 0 ]] { matchstr $(words[$i]) { -d { device := $(words[$((i+1))]); break } }; }; matchstr $prev { -d { _filedir pkg _filedir -d } -a|-r|-V { _filedir } -k|-s|-R { _filedir -d } -P|-k|-x { } * { if [[ ${cur} == -* ]] { var opts = '"-a -A -d -k -n -M -P -r -R -s -v -V -x'" global COMPREPLY := '( '$(compgen -W "${opts}" -- ${cur}) ) } else { var pkginst_list = '' if [[ -d $device ]] { for filedir in [$[/bin/ls -1 $device]] { if [[ -d "$device/$filedir" ]] && [[ -f "$device/$filedir/pkginfo" ]] { pkginst_list := '( '${pkginst_list[@]:-} "$filedir" ) } } pkginst_list := $(pkginst_list[@]) } else { pkginst_list := $[strings $[dequote $device] | \ command grep "^PKG=" | sort -u | cut -d= -f2] } global COMPREPLY := '( '$(compgen -W "$pkginst_list" -- ${cur}) ) } } } } && complete -F _pkgadd pkgadd # ex: ts=4 sw=4 et filetype=sh (CommandList children: [ (AndOr children: [ (FuncDef name: _pkgadd body: (BraceGroup children: [ (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs:(LhsName name:cur) op:Equal spids:[20]) (assign_pair lhs:(LhsName name:prev) op:Equal spids:[22]) (assign_pair lhs:(LhsName name:words) op:Equal spids:[24]) (assign_pair lhs:(LhsName name:cword) op:Equal spids:[26]) ] spids: [18] ) (AndOr children: [ (C {(_init_completion)} {(-n)} {(Lit_Other ":")}) (ControlFlow token:) ] op_id: Op_DPipe ) (Sentence child: (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:device) op: Equal rhs: {(/var/spool/pkg)} spids: [55] ) ] spids: [53] ) terminator: ) (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:i) op: Equal rhs: {($ VSub_Name "$cword")} spids: [62] ) ] spids: [60] ) (Sentence child: (While cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_gt left: { (ArithSubPart anode: (UnaryAssign op_id: Node_PostDMinus child: (LhsName name:i) ) spids: [70 74] ) } right: {(0)} ) ) terminator: ) ] body: (DoGroup children: [ (Sentence child: (Case to_match: { (DQ (BracedVarSub token: bracket_op: (ArrayIndex expr: (ArithWord w:{($ VSub_Name "$i")}) ) spids: [89 94] ) ) } arms: [ (case_arm pat_list: [{(-d)}] action: [ (Sentence child: (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:device) op: Equal rhs: { (DQ (BracedVarSub token: bracket_op: (ArrayIndex expr: (ArithWord w: { (ArithSubPart anode: (ArithBinary op_id: Arith_Plus left: (ArithVarRef name: i ) right: (ArithWord w: {(Lit_Digits 1)} ) ) spids: [109 114] ) } ) ) spids: [106 116] ) ) } spids: [104] ) ] spids: [104] ) terminator: ) (ControlFlow token: ) ] spids: [100 101 124 -1] ) ] spids: [86 97 127] ) terminator: ) ] spids: [83 131] ) ) terminator: ) (Case to_match: {($ VSub_Name "$prev")} arms: [ (case_arm pat_list: [{(-d)}] action: [(C {(_filedir)} {(pkg)}) (C {(_filedir)} {(-d)})] spids: [144 145 158 -1] ) (case_arm pat_list: [{(-a)} {(-r)} {(-V)}] action: [(C {(_filedir)})] spids: [161 166 172 -1] ) (case_arm pat_list: [{(-k)} {(-s)} {(-R)}] action: [(C {(_filedir)} {(-d)})] spids: [175 180 188 -1] ) (case_arm pat_list:[{(-P)}{(-k)}{(-x)}] spids:[191196199-1]) (case_arm pat_list: [{(Lit_Other "*")}] action: [ (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {(${ VSub_Name cur)} right: {(-) (Lit_Other "*")} ) ) terminator: ) ] action: [ (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:opts) op: Equal rhs: {(DQ ("-a -A -d -k -n -M -P -r -R -s -v -V -x"))} spids: [228] ) ] spids: [226] ) (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 (${ VSub_Name opts))} {(--)} {(${ VSub_Name cur)} ) ] ) left_token: spids: [237 253] ) } ] ) } spids: [234] ) ] spids: [234] ) ] spids: [-1 223] ) ] else_action: [ (Assignment keyword: Assign_Local pairs: [ (assign_pair lhs: (LhsName name:pkginst_list) op: Equal spids: [263] ) ] spids: [261] ) (If arms: [ (if_arm cond: [ (Sentence child: (DBracket expr: (BoolUnary op_id: BoolUnary_d child: {($ VSub_Name "$device")} ) ) terminator: ) ] action: [ (ForEach iter_name: filedir iter_words: [ { (CommandSubPart command_list: (CommandList children: [ (C {(/bin/ls)} {(-1)} {($ VSub_Name "$device")}) ] ) left_token: spids: [286 292] ) } ] do_arg_iter: False body: (DoGroup children: [ (If arms: [ (if_arm cond: [ (Sentence child: (AndOr children: [ (DBracket expr: (BoolUnary op_id: BoolUnary_d child: { (DQ ($ VSub_Name "$device") (/) ($ VSub_Name "$filedir") ) } ) ) (DBracket expr: (BoolUnary op_id: BoolUnary_f child: { (DQ ($ VSub_Name "$device") (/) ($ VSub_Name "$filedir") (/pkginfo) ) } ) ) ] op_id: Op_DAmp ) terminator: ) ] action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:pkginst_list) op: PlusEqual rhs: { (ArrayLiteralPart words: [ { (BracedVarSub token: bracket_op: (WholeArray op_id: Lit_At ) suffix_op: (StringUnary op_id: VTest_ColonHyphen arg_word: {} ) spids: [334 340] ) } {(DQ ($ VSub_Name "$filedir"))} ] ) } spids: [331] ) ] spids: [331] ) ] spids: [-1 328] ) ] spids: [-1 349] ) ] spids: [295 352] ) spids: [285 293] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:pkginst_list) op: Equal rhs: { (DQ (BracedVarSub token: bracket_op: (WholeArray op_id:Lit_At) spids: [357 362] ) ) } spids: [355] ) ] spids: [355] ) ] spids: [-1 277] ) ] else_action: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:pkginst_list) op: Equal rhs: { (CommandSubPart command_list: (CommandList children: [ (Pipeline children: [ (C {(strings)} { (CommandSubPart command_list: (CommandList children: [ (C {(dequote)} {($ VSub_Name "$device")} ) ] ) left_token: spids: [373 377] ) } ) (C {(command)} {(grep)} {(DQ ("^PKG="))}) (C {(sort)} {(-u)}) (C {(cut)} {(-d) (Lit_Other "=")} {(-f2)}) ] negated: False ) ] ) left_token: spids: [370 405] ) } spids: [369] ) ] spids: [369] ) ] spids: [366 408] ) (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 ($ VSub_Name "$pkginst_list"))} {(--)} {(${ VSub_Name cur)} ) ] ) left_token: spids: [414 428] ) } ] ) } spids: [411] ) ] spids: [411] ) ] spids: [258 433] ) ] spids: [202 203 -1 436] ) ] spids: [136 140 436] ) ] spids: [15] ) spids: [10 14] ) (C {(complete)} {(-F)} {(_pkgadd)} {(pkgadd)}) ] op_id: Op_DAmp ) ] )