aboutsummaryrefslogtreecommitdiffstats
path: root/zsh
diff options
context:
space:
mode:
authorjason2019-10-09 16:38:12 -0600
committerjason2019-10-09 16:38:12 -0600
commitd2dbb08a34958ad9d5be183dea1d7c110b8ce40d (patch)
tree9064f06f08a308cdbe3f98242f48327f5bb02bba /zsh
parent6c7b4d38f8a62cf98eb2a9810959f012cc2d160c (diff)
downloaddotfiles-d2dbb08a34958ad9d5be183dea1d7c110b8ce40d.tar.gz
dotfiles-d2dbb08a34958ad9d5be183dea1d7c110b8ce40d.zip
add docker-machine to zsh
Diffstat (limited to 'zsh')
-rw-r--r--zsh/.zsh/custom/plugins/docker-machine/_docker-machine359
-rw-r--r--zsh/.zsh/custom/plugins/docker-machine/docker-machine-prompt.bash47
-rw-r--r--zsh/.zsh/custom/plugins/docker-machine/docker-machine.plugin.zsh1
-rw-r--r--zsh/.zshrc12
4 files changed, 415 insertions, 4 deletions
diff --git a/zsh/.zsh/custom/plugins/docker-machine/_docker-machine b/zsh/.zsh/custom/plugins/docker-machine/_docker-machine
new file mode 100644
index 0000000..7c19ba8
--- /dev/null
+++ b/zsh/.zsh/custom/plugins/docker-machine/_docker-machine
@@ -0,0 +1,359 @@
1#compdef docker-machine
2# Description
3# -----------
4# zsh completion for docker-machine
5# https://github.com/leonhartX/docker-machine-zsh-completion
6# -------------------------------------------------------------------------
7# Version
8# -------
9# 0.1.1
10# -------------------------------------------------------------------------
11# Authors
12# -------
13# * Ke Xu <leonhartx.k@gmail.com>
14# -------------------------------------------------------------------------
15# Inspiration
16# -----------
17# * @sdurrheimer docker-compose-zsh-completion https://github.com/sdurrheimer/docker-compose-zsh-completion
18# * @ilkka _docker-machine
19
20
21__docker-machine_get_hosts() {
22 [[ $PREFIX = -* ]] && return 1
23 local state
24 declare -a hosts
25 state=$1; shift
26 if [[ $state != all ]]; then
27 hosts=(${(f)"$(_call_program commands docker-machine ls -q --filter state=$state)"})
28 else
29 hosts=(${(f)"$(_call_program commands docker-machine ls -q)"})
30 fi
31 _describe 'host' hosts "$@" && ret=0
32 return ret
33}
34
35__docker-machine_hosts_with_state() {
36 declare -a hosts
37 hosts=(${(f)"$(_call_program commands docker-machine ls -f '{{.Name}}\:{{.DriverName}}\({{.State}}\)\ {{.URL}}')"})
38 _describe 'host' hosts
39}
40
41__docker-machine_hosts_all() {
42 __docker-machine_get_hosts all "$@"
43}
44
45__docker-machine_hosts_running() {
46 __docker-machine_get_hosts Running "$@"
47}
48
49__docker-machine_get_swarm() {
50 declare -a swarms
51 swarms=(${(f)"$(_call_program commands docker-machine ls -f {{.Swarm}} | awk '{print $1}')"})
52 _describe 'swarm' swarms
53}
54
55__docker-machine_hosts_and_files() {
56 _alternative "hosts:host:__docker-machine_hosts_all -qS ':'" 'files:files:_path_files'
57}
58
59__docker-machine_filters() {
60 [[ $PREFIX = -* ]] && return 1
61 integer ret=1
62
63 if compset -P '*='; then
64 case "${${words[-1]%=*}#*=}" in
65 (driver)
66 _describe -t driver-filter-opts "driver filter" opts_driver && ret=0
67 ;;
68 (swarm)
69 __docker-machine_get_swarm && ret=0
70 ;;
71 (state)
72 opts_state=('Running' 'Paused' 'Saved' 'Stopped' 'Stopping' 'Starting' 'Error')
73 _describe -t state-filter-opts "state filter" opts_state && ret=0
74 ;;
75 (name)
76 __docker-machine_hosts_all && ret=0
77 ;;
78 (label)
79 _message 'label' && ret=0
80 ;;
81 *)
82 _message 'value' && ret=0
83 ;;
84 esac
85 else
86 opts=('driver' 'swarm' 'state' 'name' 'label')
87 _describe -t filter-opts "filter" opts -qS "=" && ret=0
88 fi
89 return ret
90}
91
92__get_swarm_discovery() {
93 declare -a masters serivces
94 local service
95 services=()
96 masters=($(docker-machine ls -f {{.Swarm}} |grep '(master)' |awk '{print $1}'))
97 for master in $masters; do
98 service=${${${(f)"$(_call_program commands docker-machine inspect -f '{{.HostOptions.SwarmOptions.Discovery}}:{{.Name}}' $master)"}/:/\\:}}
99 services=($services $service)
100 done
101 _describe -t services "swarm service" services && ret=0
102 return ret
103}
104
105__get_create_argument() {
106 typeset -g docker_machine_driver
107 if [[ CURRENT -le 2 ]]; then
108 docker_machine_driver="none"
109 elif [[ CURRENT > 2 && $words[CURRENT-2] = '-d' || $words[CURRENT-2] = '--driver' ]]; then
110 docker_machine_driver=$words[CURRENT-1]
111 elif [[ $words[CURRENT-1] =~ '^(-d|--driver)=' ]]; then
112 docker_machine_driver=${${words[CURRENT-1]}/*=/}
113 fi
114 local driver_opt_cmd
115 local -a opts_provider opts_common opts_read_argument
116 opts_read_argument=(
117 ": :->argument"
118 )
119 opts_common=(
120 $opts_help \
121 '(--driver -d)'{--driver=,-d=}'[Driver to create machine with]:dirver:->driver-option' \
122 '--engine-install-url=[Custom URL to use for engine installation]:url' \
123 '*--engine-opt=[Specify arbitrary flags to include with the created engine in the form flag=value]:flag' \
124 '*--engine-insecure-registry=[Specify insecure registries to allow with the created engine]:registry' \
125 '*--engine-registry-mirror=[Specify registry mirrors to use]:mirror' \
126 '*--engine-label=[Specify labels for the created engine]:label' \
127 '--engine-storage-driver=[Specify a storage driver to use with the engine]:storage-driver:->storage-driver-option' \
128 '*--engine-env=[Specify environment variables to set in the engine]:environment' \
129 '--swarm[Configure Machine with Swarm]' \
130 '--swarm-image=[Specify Docker image to use for Swarm]:image' \
131 '--swarm-master[Configure Machine to be a Swarm master]' \
132 '--swarm-discovery=[Discovery service to use with Swarm]:service:->swarm-service' \
133 '--swarm-strategy=[Define a default scheduling strategy for Swarm]:strategy:(spread binpack random)' \
134 '*--swarm-opt=[Define arbitrary flags for swarm]:flag' \
135 '*--swarm-join-opt=[Define arbitrary flags for Swarm join]:flag' \
136 '--swarm-host=[ip/socket to listen on for Swarm master]:host' \
137 '--swarm-addr=[addr to advertise for Swarm (default: detect and use the machine IP)]:address' \
138 '--swarm-experimental[Enable Swarm experimental features]' \
139 '*--tls-san=[Support extra SANs for TLS certs]:option'
140 )
141 driver_opt_cmd="docker-machine create -d $docker_machine_driver | grep $docker_machine_driver | sed -e 's/\(--.*\)\ *\[\1[^]]*\]/*\1/g' -e 's/\(\[[^]]*\)/\\\\\\1\\\\/g' -e 's/\".*\"\(.*\)/\1/g' | awk '{printf \"%s[\", \$1; for(i=2;i<=NF;i++) {printf \"%s \", \$i}; print \"]\"}'"
142 if [[ $docker_machine_driver != "none" ]]; then
143 opts_provider=(${(f)"$(_call_program commands $driver_opt_cmd)"})
144 _arguments \
145 $opts_provider \
146 $opts_read_argument \
147 $opts_common && ret=0
148 else
149 _arguments $opts_common && ret=0
150 fi
151 case $state in
152 (driver-option)
153 _describe -t driver-option "driver" opts_driver && ret=0
154 ;;
155 (storage-driver-option)
156 _describe -t storage-driver-option "storage driver" opts_storage_driver && ret=0
157 ;;
158 (swarm-service)
159 __get_swarm_discovery && ret=0
160 ;;
161 (argument)
162 ret=0
163 ;;
164 esac
165 return ret
166}
167
168
169__docker-machine_subcommand() {
170 local -a opts_help
171 opts_help=("(- :)--help[Print usage]")
172 local -a opts_only_host opts_driver opts_storage_driver opts_stragery
173 opts_only_host=(
174 "$opts_help"
175 "*:host:__docker-machine_hosts_all"
176 )
177 opts_driver=('amazonec2' 'azure' 'digitalocean' 'exoscale' 'generic' 'google' 'hyperv' 'none' 'openstack' 'rackspace' 'softlayer' 'virtualbox' 'vmwarefusion' 'vmwarevcloudair' 'vmwarevsphere')
178 opts_storage_driver=('overlay' 'aufs' 'btrfs' 'devicemapper' 'vfs' 'zfs')
179 integer ret=1
180
181 case "$words[1]" in
182 (active)
183 _arguments \
184 $opts_help \
185 '(--timeout -t)'{--timeout=,-t=}'[Timeout in seconds, default to 10s]:seconds' && ret=0
186 ;;
187 (config)
188 _arguments \
189 $opts_help \
190 '--swarm[Display the Swarm config instead of the Docker daemon]' \
191 "*:host:__docker-machine_hosts_all" && ret=0
192 ;;
193 (create)
194 __get_create_argument
195 ;;
196 (env)
197 _arguments \
198 $opts_help \
199 '--swarm[Display the Swarm config instead of the Docker daemon]' \
200 '--shell=[Force environment to be configured for a specified shell: \[fish, cmd, powershell\], default is auto-detect]:shell' \
201 '(--unset -u)'{--unset,-u}'[Unset variables instead of setting them]' \
202 '--no-proxy[Add machine IP to NO_PROXY environment variable]' \
203 '*:host:__docker-machine_hosts_running' && ret=0
204 ;;
205 (help)
206 _arguments ':subcommand:__docker-machine_commands' && ret=0
207 ;;
208 (inspect)
209 _arguments \
210 $opts_help \
211 '(--format -f)'{--format=,-f=}'[Format the output using the given go template]:template' \
212 '*:host:__docker-machine_hosts_all' && ret=0
213 ;;
214 (ip)
215 _arguments \
216 $opts_help \
217 '*:host:__docker-machine_hosts_running' && ret=0
218 ;;
219 (kill)
220 _arguments \
221 $opts_help \
222 '*:host:__docker-machine_hosts_with_state' && ret=0
223 ;;
224 (ls)
225 _arguments \
226 $opts_help \
227 '(--quiet -q)'{--quiet,-q}'[Enable quiet mode]' \
228 '*--filter=[Filter output based on conditions provided]:filter:->filter-options' \
229 '(--timeout -t)'{--timeout=,-t=}'[Timeout in seconds, default to 10s]:seconds' \
230 '(--format -f)'{--format=,-f=}'[Pretty-print machines using a Go template]:template' && ret=0
231 case $state in
232 (filter-options)
233 __docker-machine_filters && ret=0
234 ;;
235 esac
236 ;;
237 (provision)
238 _arguments $opts_only_host && ret=0
239 ;;
240 (regenerate-certs)
241 _arguments \
242 $opts_help \
243 '(--force -f)'{--force,-f}'[Force rebuild and do not prompt]' \
244 '*:host:__docker-machine_hosts_all' && ret=0
245 ;;
246 (restart)
247 _arguments \
248 $opts_help \
249 '*:host:__docker-machine_hosts_with_state' && ret=0
250 ;;
251 (rm)
252 _arguments \
253 $opts_help \
254 '(--force -f)'{--force,-f}'[Remove local configuration even if machine cannot be removed, also implies an automatic yes (`-y`)]' \
255 '-y[Assumes automatic yes to proceed with remove, without prompting further user confirmation]' \
256 '*:host:__docker-machine_hosts_with_state' && ret=0
257 ;;
258 (scp)
259 _arguments \
260 $opts_help \
261 '(--recursive -r)'{--recursive,-r}'[Copy files recursively (required to copy directories))]' \
262 '*:files:__docker-machine_hosts_and_files' && ret=0
263 ;;
264 (ssh)
265 _arguments \
266 $opts_help \
267 '*:host:__docker-machine_hosts_running' && ret=0
268 ;;
269 (start)
270 _arguments \
271 $opts_help \
272 '*:host:__docker-machine_hosts_with_state' && ret=0
273 ;;
274 (status)
275 _arguments $opts_only_host && ret=0
276 ;;
277 (stop)
278 _arguments \
279 $opts_help \
280 '*:host:__docker-machine_hosts_with_state' && ret=0
281 ;;
282 (upgrade)
283 _arguments $opts_only_host && ret=0
284 ;;
285 (url)
286 _arguments \
287 $opts_help \
288 '*:host:__docker-machine_hosts_running' && ret=0
289 ;;
290 esac
291
292 return ret
293}
294
295
296__docker-machine_commands() {
297 local cache_policy
298
299 zstyle -s ":completion:${curcontext}:" cache-policy cache_policy
300 if [[ -z "$cache_policy" ]]; then
301 zstyle ":completion:${curcontext}:" cache-policy __docker-machine_caching_policy
302 fi
303
304 if ( [[ ${+_docker_machine_subcommands} -eq 0 ]] || _cache_invalid docker_machine_subcommands) \
305 && ! _retrieve_cache docker_machine_subcommands;
306 then
307 local -a lines
308 lines=(${(f)"$(_call_program commands docker-machine 2>&1)"})
309 _docker_machine_subcommands=(${${${lines[$((${lines[(i)Commands:]} + 1)),${lines[(I) *]}]}## #}/$'\t'##/:})
310 (( $#_docker_machine_subcommands > 0 )) && _store_cache docker_machine_subcommands _docker_machine_subcommands
311 fi
312 _describe -t docker-machine-commands "docker-machine command" _docker_machine_subcommands
313}
314
315__docker-machine_caching_policy() {
316 oldp=( "$1"(Nmh+1) )
317 (( $#oldp ))
318}
319
320_docker-machine() {
321 if [[ $service != docker-machine ]]; then
322 _call_function - _$service
323 return
324 fi
325
326 local curcontext="$curcontext" state line
327 integer ret=1
328 typeset -A opt_args
329
330 _arguments -C \
331 "(- :)"{-h,--help}"[Show help]" \
332 "(-D --debug)"{-D,--debug}"[Enable debug mode]" \
333 '(-s --stroage-path)'{-s,--storage-path}'[Configures storage path]:file:_files' \
334 '--tls-ca-cert[CA to verify remotes against]:file:_files' \
335 '--tls-ca-key[Private key to generate certificates]:file:_files' \
336 '--tls-client-cert[Client cert to use for TLS]:file:_files' \
337 '--tls-client-key[Private key used in client TLS auth]:file:_files' \
338 '--github-api-token[Token to use for requests to the Github API]' \
339 '--native-ssh[Use the native (Go-based) SSH implementation.]' \
340 '--bugsnag-api-token[BugSnag API token for crash reporting]' \
341 '(- :)'{-v,--version}'[Print the version]' \
342 "(-): :->command" \
343 "(-)*:: :->option-or-argument" && ret=0
344
345 case $state in
346 (command)
347 __docker-machine_commands && ret=0
348 ;;
349 (option-or-argument)
350 curcontext=${curcontext%:*:*}:docker-machine-$words[1]:
351 __docker-machine_subcommand && ret=0
352 ret=0
353 ;;
354 esac
355
356 return ret
357}
358
359_docker-machine "$@"
diff --git a/zsh/.zsh/custom/plugins/docker-machine/docker-machine-prompt.bash b/zsh/.zsh/custom/plugins/docker-machine/docker-machine-prompt.bash
new file mode 100644
index 0000000..0a6e43a
--- /dev/null
+++ b/zsh/.zsh/custom/plugins/docker-machine/docker-machine-prompt.bash
@@ -0,0 +1,47 @@
1#
2# bash prompt support for docker-machine
3#
4# This script allows you to see the active machine in your bash prompt.
5#
6# To enable:
7# 1a. Copy this file somewhere and source it in your .bashrc
8# source /some/where/docker-machine-prompt.bash
9# 1b. Alternatively, just copy this file into into /etc/bash_completion.d
10# 2. Change your PS1 to call __docker-machine-ps1 as command-substitution
11# PS1='[\u@\h \W$(__docker_machine_ps1 " [%s]")]\$ '
12#
13# Configuration:
14#
15# DOCKER_MACHINE_PS1_SHOWSTATUS
16# When set, the machine status is indicated in the prompt. This can be slow,
17# so use with care.
18#
19
20__docker_machine_ps1 () {
21 local format=${1:- [%s]}
22 if test ${DOCKER_MACHINE_NAME}; then
23 local status
24 if test ${DOCKER_MACHINE_PS1_SHOWSTATUS:-false} = true; then
25 status=$(docker-machine status ${DOCKER_MACHINE_NAME})
26 case ${status} in
27 Running)
28 status=' R'
29 ;;
30 Stopping)
31 status=' R->S'
32 ;;
33 Starting)
34 status=' S->R'
35 ;;
36 Error|Timeout)
37 status=' E'
38 ;;
39 *)
40 # Just consider everything elase as 'stopped'
41 status=' S'
42 ;;
43 esac
44 fi
45 printf -- "${format}" "${DOCKER_MACHINE_NAME}${status}"
46 fi
47}
diff --git a/zsh/.zsh/custom/plugins/docker-machine/docker-machine.plugin.zsh b/zsh/.zsh/custom/plugins/docker-machine/docker-machine.plugin.zsh
new file mode 100644
index 0000000..b7e283f
--- /dev/null
+++ b/zsh/.zsh/custom/plugins/docker-machine/docker-machine.plugin.zsh
@@ -0,0 +1 @@
source $ZSH_CUSTOM/plugins/docker-machine/docker-machine-prompt.bash
diff --git a/zsh/.zshrc b/zsh/.zshrc
index 62ce98a..2aa0ce4 100644
--- a/zsh/.zshrc
+++ b/zsh/.zshrc
@@ -43,12 +43,12 @@ DISABLE_CORRECTION="true"
43# HIST_STAMPS="mm/dd/yyyy" 43# HIST_STAMPS="mm/dd/yyyy"
44 44
45# Would you like to use another custom folder than $ZSH/custom? 45# Would you like to use another custom folder than $ZSH/custom?
46# ZSH_CUSTOM=/path/to/new-custom-folder 46ZSH_CUSTOM=$HOME/.zsh/custom
47 47
48# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*) 48# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
49# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/ 49# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
50# Example format: plugins=(rails git textmate ruby lighthouse) 50# Example format: plugins=(rails git textmate ruby lighthouse)
51plugins=(git git-extras docker docker-compose gpg-agent pep8 pip pyenv pylint python web-search wd) 51plugins=(git git-extras docker docker-compose docker-machine gpg-agent pep8 pip pyenv pylint python web-search wd)
52 52
53ZSH=~/.oh-my-zsh 53ZSH=~/.oh-my-zsh
54 54
@@ -57,10 +57,13 @@ export LANG=en_US.UTF-8
57export MANPATH="/usr/local/man:$MANPATH" 57export MANPATH="/usr/local/man:$MANPATH"
58 58
59# Enable direnv (https://github.com/direnv/direnv/) 59# Enable direnv (https://github.com/direnv/direnv/)
60eval "$(direnv hook zsh)" 60if [ -x direnv ]; then
61# PATH setup 61 eval "$(direnv hook zsh)"
62fi
62 63
64# PATH setup
63export PATH="$HOME/bin:$HOME/.cargo/bin:/usr/local/go/bin/:$PATH" 65export PATH="$HOME/bin:$HOME/.cargo/bin:/usr/local/go/bin/:$PATH"
66
64if [ -f /usr/local/go/bin/go ]; then 67if [ -f /usr/local/go/bin/go ]; then
65 export PATH="$PATH:$GOROOT/bin:$(go env GOPATH)/bin" 68 export PATH="$PATH:$GOROOT/bin:$(go env GOPATH)/bin"
66fi 69fi
@@ -134,6 +137,7 @@ show_virtual_env() {
134} 137}
135 138
136#PS1='$(show_virtual_env)'$PS1 139#PS1='$(show_virtual_env)'$PS1
140PS1="$PS1 $(__docker_machine_ps1)"
137 141
138[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh 142[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
139 143