Skip to content

Commit b28568a

Browse files
committed
Linked bash completion with 'scw _completion' command (#45)
1 parent 0c23a71 commit b28568a

File tree

1 file changed

+19
-39
lines changed
  • contrib/completion/bash

1 file changed

+19
-39
lines changed

contrib/completion/bash/scw

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -26,78 +26,58 @@
2626
# Inspired from https://github.com/docker/docker/blob/master/contrib/completion/bash/docker
2727

2828
__scw_q() {
29-
scw ${host:+-H "$host"} 2>/dev/null "$@"
29+
scw $@ 2>/dev/null
3030
}
3131

3232
__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") )
4337
}
4438

4539
__scw_servers_running() {
46-
__scw_servers_all '.State.Running'
40+
__scw_servers_all
4741
}
4842

4943
__scw_servers_stopped() {
50-
__scw_servers_all 'not .State.Running'
44+
__scw_servers_all
5145
}
5246

5347
__scw_servers_pauseable() {
54-
__scw_servers_all 'and .State.Running (not .State.Paused)'
48+
__scw_servers_all
5549
}
5650

5751
__scw_servers_unpauseable() {
58-
__scw_servers_all '.State.Paused'
52+
__scw_servers_all
5953
}
6054

6155
__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
6757
}
6858

6959
__scw_server_ids() {
70-
# local servers=( $(__scw_q ps -aq) )
71-
# COMPREPLY=( $(compgen -W "${servers[*]}" -- "$cur") )
72-
COMPREPLY=( )
60+
__scw_servers_all
7361
}
7462

7563
__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") )
7966
}
8067

8168
__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
8670
}
8771

8872
__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
9374
}
9475

9576
__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[@]}" )
10181
}
10282

10383
__scw_pos_first_nonflag() {

0 commit comments

Comments
 (0)