763bf6374cf15162e6cea1528fb7d08c38037c65
- Author
- Robby Russell <robby@planetargon.com>
- Committer
- Robby Russell <robby@planetargon.com>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/plugins/scw/README.md b/plugins/scw/README.md
2new file mode 100644
3index 0000000000000000000000000000000000000000..d2312c2e5cba0ead32f1459ed5ed574b81e14bc5
4--- /dev/null
5+++ b/plugins/scw/README.md
6@@ -0,0 +1,7 @@
7+## Scaleway CLI autocomplete plugin
8+
9+[scw](https://github.com/scaleway/scaleway-cli): Manage Bare Metal servers from Command Line (as easily as with Docker)
10+
11+- Adds autocomplete options for all `scw` commands.
12+
13+Maintainer : Manfred Touron ([@moul](https://github.com/moul))
14diff --git a/plugins/scw/_scw b/plugins/scw/_scw
15new file mode 100644
16index 0000000000000000000000000000000000000000..f9fdf916e761728b398f7ed04f0399457d419026
17--- /dev/null
18+++ b/plugins/scw/_scw
19@@ -0,0 +1,333 @@
20+#compdef scw
21+#
22+# zsh completion for scw (http://scaleway.com)
23+#
24+# Inspired by https://github.com/felixr/docker-zsh-completion
25+
26+__scw_get_servers() {
27+ local expl
28+ declare -a servers
29+ servers=(${(f)"$(_call_program commands scw _completion servers-names)"})
30+ _describe -t servers "servers" servers
31+}
32+
33+__scw_stoppedservers() {
34+ __scw_get_servers
35+}
36+
37+__scw_runningservers() {
38+ __scw_get_servers
39+}
40+
41+__scw_servers () {
42+ __scw_get_servers
43+}
44+
45+__scw_images () {
46+ local expl
47+ declare -a images
48+ images=(${(f)"$(_call_program commands scw _completion images-names)"})
49+ _describe -t images "images" images
50+}
51+
52+__scw_images_and_snapshots () {
53+ __scw_images
54+ __scw_snapshots
55+}
56+
57+__scw_snapshots () {
58+ local expl
59+ declare -a snapshots
60+ snapshots=(${(f)"$(_call_program commands scw _completion --prefix snapshots-names)"})
61+ _describe -t snapshots "snapshots" snapshots
62+}
63+
64+__scw_bootscripts () {
65+ local expl
66+ declare -a bootscripts
67+ bootscripts=(${(f)"$(_call_program commands scw _completion bootscripts-names)"})
68+ _describe -t bootscripts "bootscripts" bootscripts
69+}
70+
71+__scw_tags() {
72+ __scw_images
73+}
74+
75+__scw_repositories_with_tags() {
76+ __scw_images
77+}
78+
79+__scw_search() {
80+ # declare -a scwsearch
81+ local cache_policy
82+ zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
83+ if [[ -z "$cache_policy" ]]; then
84+ zstyle ":completion:${curcontext}:" cache-policy __scw_caching_policy
85+ fi
86+
87+ local searchterm cachename
88+ searchterm="${words[$CURRENT]%/}"
89+ cachename=_scw-search-$searchterm
90+
91+ local expl
92+ local -a result
93+ if ( [[ ${(P)+cachename} -eq 0 ]] || _cache_invalid ${cachename#_} ) \
94+ && ! _retrieve_cache ${cachename#_}; then
95+ _message "Searching for ${searchterm}..."
96+ result=(${${${(f)"$(_call_program commands scw search ${searchterm})"}%% *}[2,-1]})
97+ _store_cache ${cachename#_} result
98+ fi
99+ _wanted scwsearch expl 'available images' compadd -a result
100+}
101+
102+__scw_caching_policy()
103+{
104+ oldp=( "$1"(Nmh+1) ) # 1 hour
105+ (( $#oldp ))
106+}
107+
108+
109+__scw_repositories () {
110+ __scw_images
111+}
112+
113+__scw_commands () {
114+ # local -a _scw_subcommands
115+ local cache_policy
116+
117+ zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
118+ if [[ -z "$cache_policy" ]]; then