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