summaryrefslogtreecommitdiff
path: root/.local/share/bash-completion/completions/go2
blob: 45406b90d95462e36361f358141aa9814e5fe8b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
#!bash 
 
# Generated with perl module App::Spec v0.013 
 
_go2() {
 
    COMPREPLY=()
    local program=go2
    local cur prev words cword
    _init_completion -n : || return
    declare -a FLAGS
    declare -a OPTIONS
    declare -a MYWORDS
 
    local INDEX=`expr $cword - 1`
    MYWORDS=("${words[@]:1:$cword}")
 
    FLAGS=('--help' 'Show command help' '-h' 'Show command help')
    OPTIONS=('--config-file' 'load configuration from this file' '-C' 'load configuration from this file')
    __go2_handle_options_flags
 
    case $INDEX in
 
    0)
        __comp_current_options || return
        __go2_dynamic_comp 'commands' 'connect'$'\t''connect to the hosts'$'\n''cp'$'\t''copy files from/to hosts'$'\n''cssh'$'\t''connect to the hosts via ClusterSSH'$'\n''help'$'\t''Show command help'$'\n''list'$'\t''list the hosts'$'\n''wipe-cache'$'\t''removes all cached machine information'
 
    ;;
    *)
    # subcmds 
    case ${MYWORDS[0]} in
      _meta)
        __go2_handle_options_flags
        case $INDEX in
 
        1)
            __comp_current_options || return
            __go2_dynamic_comp 'commands' 'completion'$'\t''Shell completion functions'$'\n''pod'$'\t''Pod documentation'
 
        ;;
        *)
        # subcmds 
        case ${MYWORDS[1]} in
          completion)
            __go2_handle_options_flags
            case $INDEX in
 
            2)
                __comp_current_options || return
                __go2_dynamic_comp 'commands' 'generate'$'\t''Generate self completion'
 
            ;;
            *)
            # subcmds 
            case ${MYWORDS[2]} in
              generate)
                FLAGS+=('--zsh' 'for zsh' '--bash' 'for bash')
                OPTIONS+=('--name' 'name of the program (optional, override name in spec)')
                __go2_handle_options_flags
                case ${MYWORDS[$INDEX-1]} in
                  --config-file|-C)
                  ;;
                  --name)
                  ;;
 
                esac
                case $INDEX in
 
                *)
                    __comp_current_options || return
                ;;
                esac
              ;;
            esac
 
            ;;
            esac
          ;;
          pod)
            __go2_handle_options_flags
            case $INDEX in
 
            2)
                __comp_current_options || return
                __go2_dynamic_comp 'commands' 'generate'$'\t''Generate self pod'
 
            ;;
            *)
            # subcmds 
            case ${MYWORDS[2]} in
              generate)
                __go2_handle_options_flags
                __comp_current_options true || return # no subcmds, no params/opts 
              ;;
            esac
 
            ;;
            esac
          ;;
        esac
 
        ;;
        esac
      ;;
      connect)
        FLAGS+=('--all' 'SSH to every matching machine, one after the other, instead of the best match only' '-a' 'SSH to every matching machine, one after the other, instead of the best match only' '--verbose' 'verbose output' '-v' 'verbose output' '--external' 'access the machines from an external address, if you'"\\'"'re not in the office or on the VPN' '-e' 'access the machines from an external address, if you'"\\'"'re not in the office or on the VPN' '--dry-run' 'don'"\\'"'t run the ssh command, just print it' '-d' 'don'"\\'"'t run the ssh command, just print it')
        __go2_handle_options_flags
        case ${MYWORDS[$INDEX-1]} in
          --config-file|-C)
          ;;
 
        esac
        case $INDEX in
          1)
              __comp_current_options || return
                _go2_connect_param_regex_completion
          ;;
 
 
        *)
            __comp_current_options || return
        ;;
        esac
      ;;
      cp)
        FLAGS+=('--all' 'SSH to every matching machine, one after the other, instead of the best match only' '-a' 'SSH to every matching machine, one after the other, instead of the best match only' '--verbose' 'verbose output' '-v' 'verbose output' '--external' 'access the machines from an external address, if you'"\\'"'re not in the office or on the VPN' '-e' 'access the machines from an external address, if you'"\\'"'re not in the office or on the VPN' '--dry-run' 'don'"\\'"'t run the ssh command, just print it' '-d' 'don'"\\'"'t run the ssh command, just print it' '--recursive' 'recursively copy entire directories' '-r' 'recursively copy entire directories')
        __go2_handle_options_flags
        case ${MYWORDS[$INDEX-1]} in
          --config-file|-C)
          ;;
 
        esac
        case $INDEX in
          1)
              __comp_current_options || return
                _go2_cp_param_path_completion
          ;;
 
 
        *)
            __comp_current_options || return
        ;;
        esac
      ;;
      cssh)
        FLAGS+=('--all' 'SSH to every matching machine, one after the other, instead of the best match only' '-a' 'SSH to every matching machine, one after the other, instead of the best match only' '--verbose' 'verbose output' '-v' 'verbose output' '--external' 'access the machines from an external address, if you'"\\'"'re not in the office or on the VPN' '-e' 'access the machines from an external address, if you'"\\'"'re not in the office or on the VPN')
        __go2_handle_options_flags
        case ${MYWORDS[$INDEX-1]} in
          --config-file|-C)
          ;;
 
        esac
        case $INDEX in
          1)
              __comp_current_options || return
                _go2_cssh_param_regex_completion
          ;;
 
 
        *)
            __comp_current_options || return
        ;;
        esac
      ;;
      help)
        FLAGS+=('--all' '')
        __go2_handle_options_flags
        case $INDEX in
 
        1)
            __comp_current_options || return
            __go2_dynamic_comp 'commands' 'connect'$'\n''cp'$'\n''cssh'$'\n''list'$'\n''wipe-cache'
 
        ;;
        *)
        # subcmds 
        case ${MYWORDS[1]} in
          _meta)
            __go2_handle_options_flags
            case $INDEX in
 
            2)
                __comp_current_options || return
                __go2_dynamic_comp 'commands' 'completion'$'\n''pod'
 
            ;;
            *)
            # subcmds 
            case ${MYWORDS[2]} in
              completion)
                __go2_handle_options_flags
                case $INDEX in
 
                3)
                    __comp_current_options || return
                    __go2_dynamic_comp 'commands' 'generate'
 
                ;;
                *)
                # subcmds 
                case ${MYWORDS[3]} in
                  generate)
                    __go2_handle_options_flags
                    __comp_current_options true || return # no subcmds, no params/opts 
                  ;;
                esac
 
                ;;
                esac
              ;;
              pod)
                __go2_handle_options_flags
                case $INDEX in
 
                3)
                    __comp_current_options || return
                    __go2_dynamic_comp 'commands' 'generate'
 
                ;;
                *)
                # subcmds 
                case ${MYWORDS[3]} in
                  generate)
                    __go2_handle_options_flags
                    __comp_current_options true || return # no subcmds, no params/opts 
                  ;;
                esac
 
                ;;
                esac
              ;;
            esac
 
            ;;
            esac
          ;;
          connect)
            __go2_handle_options_flags
            __comp_current_options true || return # no subcmds, no params/opts 
          ;;
          cp)
            __go2_handle_options_flags
            __comp_current_options true || return # no subcmds, no params/opts 
          ;;
          cssh)
            __go2_handle_options_flags
            __comp_current_options true || return # no subcmds, no params/opts 
          ;;
          list)
            __go2_handle_options_flags
            __comp_current_options true || return # no subcmds, no params/opts 
          ;;
          wipe-cache)
            __go2_handle_options_flags
            __comp_current_options true || return # no subcmds, no params/opts 
          ;;
        esac
 
        ;;
        esac
      ;;
      list)
        FLAGS+=('--all' 'SSH to every matching machine, one after the other, instead of the best match only' '-a' 'SSH to every matching machine, one after the other, instead of the best match only' '--verbose' 'verbose output' '-v' 'verbose output' '--external' 'access the machines from an external address, if you'"\\'"'re not in the office or on the VPN' '-e' 'access the machines from an external address, if you'"\\'"'re not in the office or on the VPN')
        __go2_handle_options_flags
        case ${MYWORDS[$INDEX-1]} in
          --config-file|-C)
          ;;
 
        esac
        case $INDEX in
          1)
              __comp_current_options || return
                _go2_list_param_regex_completion
          ;;
 
 
        *)
            __comp_current_options || return
        ;;
        esac
      ;;
      wipe-cache)
        __go2_handle_options_flags
        __comp_current_options true || return # no subcmds, no params/opts 
      ;;
    esac
 
    ;;
    esac
 
}
 
_go2_compreply() {
    local prefix=""
    cur="$(printf '%q' "$cur")"
    IFS=$'\n' COMPREPLY=($(compgen -P "$prefix" -W "$*" -- "$cur"))
    __ltrim_colon_completions "$prefix$cur"
 
    # http://stackoverflow.com/questions/7267185/bash-autocompletion-add-description-for-possible-completions 
    if [[ ${#COMPREPLY[*]} -eq 1 ]]; then # Only one completion 
        COMPREPLY=( "${COMPREPLY[0]%% -- *}" ) # Remove ' -- ' and everything after 
        COMPREPLY=( "${COMPREPLY[0]%%+( )}" ) # Remove trailing spaces 
    fi
}
 
_go2_connect_param_regex_completion() {
    local __dynamic_completion
    __dynamic_completion=$(PERL5_APPSPECRUN_SHELL=bash PERL5_APPSPECRUN_COMPLETION_PARAMETER='regex' ${words[@]})
    __go2_dynamic_comp 'regex' "$__dynamic_completion"
}
_go2_cp_param_path_completion() {
    local __dynamic_completion
    __dynamic_completion=$(PERL5_APPSPECRUN_SHELL=bash PERL5_APPSPECRUN_COMPLETION_PARAMETER='path' ${words[@]})
    __go2_dynamic_comp 'path' "$__dynamic_completion"
}
_go2_cssh_param_regex_completion() {
    local __dynamic_completion
    __dynamic_completion=$(PERL5_APPSPECRUN_SHELL=bash PERL5_APPSPECRUN_COMPLETION_PARAMETER='regex' ${words[@]})
    __go2_dynamic_comp 'regex' "$__dynamic_completion"
}
_go2_list_param_regex_completion() {
    local __dynamic_completion
    __dynamic_completion=$(PERL5_APPSPECRUN_SHELL=bash PERL5_APPSPECRUN_COMPLETION_PARAMETER='regex' ${words[@]})
    __go2_dynamic_comp 'regex' "$__dynamic_completion"
}
 
__go2_dynamic_comp() {
    local argname="$1"
    local arg="$2"
    local name desc cols desclength formatted
    local comp=()
    local max=0
 
    while read -r line; do
        name="$line"
        desc="$line"
        name="${name%$'\t'*}"
        if [[ "${#name}" -gt "$max" ]]; then
            max="${#name}"
        fi
    done <<< "$arg"
 
    while read -r line; do
        name="$line"
        desc="$line"
        name="${name%$'\t'*}"
        desc="${desc/*$'\t'}"
        if [[ -n "$desc" && "$desc" != "$name" ]]; then
            # TODO portable? 
            cols=`tput cols`
            [[ -z $cols ]] && cols=80
            desclength=`expr $cols - 4 - $max`
            formatted=`printf "%-*s -- %-*s" "$max" "$name" "$desclength" "$desc"`
            comp+=("$formatted")
        else
            comp+=("'$name'")
        fi
    done <<< "$arg"
    _go2_compreply ${comp[@]}
}
 
function __go2_handle_options() {
    local i j
    declare -a copy
    local last="${MYWORDS[$INDEX]}"
    local max=`expr ${#MYWORDS[@]} - 1`
    for ((i=0; i<$max; i++))
    do
        local word="${MYWORDS[$i]}"
        local found=
        for ((j=0; j<${#OPTIONS[@]}; j+=2))
        do
            local option="${OPTIONS[$j]}"
            if [[ "$word" == "$option" ]]; then
                found=1
                i=`expr $i + 1`
                break
            fi
        done
        if [[ -n $found && $i -lt $max ]]; then
            INDEX=`expr $INDEX - 2`
        else
            copy+=("$word")
        fi
    done
    MYWORDS=("${copy[@]}" "$last")
}
 
function __go2_handle_flags() {
    local i j
    declare -a copy
    local last="${MYWORDS[$INDEX]}"
    local max=`expr ${#MYWORDS[@]} - 1`
    for ((i=0; i<$max; i++))
    do
        local word="${MYWORDS[$i]}"
        local found=
        for ((j=0; j<${#FLAGS[@]}; j+=2))
        do
            local flag="${FLAGS[$j]}"
            if [[ "$word" == "$flag" ]]; then
                found=1
                break
            fi
        done
        if [[ -n $found ]]; then
            INDEX=`expr $INDEX - 1`
        else
            copy+=("$word")
        fi
    done
    MYWORDS=("${copy[@]}" "$last")
}
 
__go2_handle_options_flags() {
    __go2_handle_options
    __go2_handle_flags
}
 
__comp_current_options() {
    local always="$1"
    if [[ -n $always || ${MYWORDS[$INDEX]} =~ ^- ]]; then
 
      local options_spec=''
      local j=
 
      for ((j=0; j<${#FLAGS[@]}; j+=2))
      do
          local name="${FLAGS[$j]}"
          local desc="${FLAGS[$j+1]}"
          options_spec+="$name"$'\t'"$desc"$'\n'
      done
 
      for ((j=0; j<${#OPTIONS[@]}; j+=2))
      do
          local name="${OPTIONS[$j]}"
          local desc="${OPTIONS[$j+1]}"
          options_spec+="$name"$'\t'"$desc"$'\n'
      done
      __go2_dynamic_comp 'options' "$options_spec"
 
      return 1
    else
      return 0
    fi
}
 
 
complete -o default -F _go2 go2