|
26 | 26 | # Inspired from https://github.com/docker/docker/blob/master/contrib/completion/bash/docker |
27 | 27 |
|
28 | 28 | __scw_q() { |
29 | | - scw ${host:+-H "$host"} 2>/dev/null "$@" |
| 29 | + scw $@ 2>/dev/null |
30 | 30 | } |
31 | 31 |
|
32 | 32 | __scw_servers_all() { |
33 | | -# local IFS=$'\n' |
34 | | -# local servers=( $(__scw_q ps -aq --no-trunc) ) |
35 | | -# if [ "$1" ]; then |
36 | | -# servers=( $(__scw_q inspect --format "{{if $1}}{{.Id}}{{end}}" "${servers[@]}") ) |
37 | | -# fi |
38 | | -# local names=( $(__scw_q inspect --format '{{.Name}}' "${servers[@]}") ) |
39 | | -# names=( "${names[@]#/}" ) # trim off the leading "/" from the server names |
40 | | -# unset IFS |
41 | | -# COMPREPLY=( $(compgen -W "${names[*]} ${servers[*]}" -- "$cur") ) |
42 | | - COMPREPLY=( ) |
| 33 | + local IFS=$'\n' |
| 34 | + local servers=( $(__scw_q _completion servers-all) ) |
| 35 | + unset IFS |
| 36 | + COMPREPLY=( $(compgen -W "${servers[*]}" -- "$cur") ) |
43 | 37 | } |
44 | 38 |
|
45 | 39 | __scw_servers_running() { |
46 | | - __scw_servers_all '.State.Running' |
| 40 | + __scw_servers_all |
47 | 41 | } |
48 | 42 |
|
49 | 43 | __scw_servers_stopped() { |
50 | | - __scw_servers_all 'not .State.Running' |
| 44 | + __scw_servers_all |
51 | 45 | } |
52 | 46 |
|
53 | 47 | __scw_servers_pauseable() { |
54 | | - __scw_servers_all 'and .State.Running (not .State.Paused)' |
| 48 | + __scw_servers_all |
55 | 49 | } |
56 | 50 |
|
57 | 51 | __scw_servers_unpauseable() { |
58 | | - __scw_servers_all '.State.Paused' |
| 52 | + __scw_servers_all |
59 | 53 | } |
60 | 54 |
|
61 | 55 | __scw_server_names() { |
62 | | -# local servers=( $(__scw_q ps -aq --no-trunc) ) |
63 | | -# local names=( $(__scw_q inspect --format '{{.Name}}' "${servers[@]}") ) |
64 | | -# names=( "${names[@]#/}" ) # trim off the leading "/" from the server names |
65 | | -# COMPREPLY=( $(compgen -W "${names[*]}" -- "$cur") ) |
66 | | - COMPREPLY=( ) |
| 56 | + __scw_servers_all |
67 | 57 | } |
68 | 58 |
|
69 | 59 | __scw_server_ids() { |
70 | | -# local servers=( $(__scw_q ps -aq) ) |
71 | | -# COMPREPLY=( $(compgen -W "${servers[*]}" -- "$cur") ) |
72 | | - COMPREPLY=( ) |
| 60 | + __scw_servers_all |
73 | 61 | } |
74 | 62 |
|
75 | 63 | __scw_image_repos() { |
76 | | -# local repos="$(__scw_q images | awk 'NR>1 && $1 != "<none>" { print $1 }')" |
77 | | -# COMPREPLY=( $(compgen -W "$repos" -- "$cur") ) |
78 | | - COMPREPLY=( ) |
| 64 | + local repos=( $(__scw_q _completion images-all) ) |
| 65 | + COMPREPLY=( $(compgen -W "$repos" -- "$cur") ) |
79 | 66 | } |
80 | 67 |
|
81 | 68 | __scw_image_repos_and_tags() { |
82 | | -# local reposAndTags="$(__scw_q images | awk 'NR>1 && $1 != "<none>" { print $1; print $1":"$2 }')" |
83 | | -# COMPREPLY=( $(compgen -W "$reposAndTags" -- "$cur") ) |
84 | | -# __ltrim_colon_completions "$cur" |
85 | | - COMPREPLY=( ) |
| 69 | + __scw_image_repos |
86 | 70 | } |
87 | 71 |
|
88 | 72 | __scw_image_repos_and_tags_and_ids() { |
89 | | -# local images="$(__scw_q images -a --no-trunc | awk 'NR>1 { print $3; if ($1 != "<none>") { print $1; print $1":"$2 } }')" |
90 | | -# COMPREPLY=( $(compgen -W "$images" -- "$cur") ) |
91 | | -# __ltrim_colon_completions "$cur" |
92 | | - COMPREPLY=( ) |
| 73 | + __scw_image_repos |
93 | 74 | } |
94 | 75 |
|
95 | 76 | __scw_servers_and_images() { |
96 | | -# __scw_servers_all |
97 | | -# local servers=( "${COMPREPLY[@]}" ) |
98 | | -# __scw_image_repos_and_tags_and_ids |
99 | | -# COMPREPLY+=( "${servers[@]}" ) |
100 | | - COMPREPLY=( ) |
| 77 | + __scw_servers_all |
| 78 | + local servers=( "${COMPREPLY[@]}" ) |
| 79 | + __scw_image_repos_and_tags_and_ids |
| 80 | + COMPREPLY+=( "${servers[@]}" ) |
101 | 81 | } |
102 | 82 |
|
103 | 83 | __scw_pos_first_nonflag() { |
|
0 commit comments