From d9dbe8b6f6829c419d20d689b6c9581972b4c6ad Mon Sep 17 00:00:00 2001 From: Harald Albers Date: Wed, 25 Jan 2017 10:24:27 +0100 Subject: [PATCH] Add windows specific bash completion for `docker run|create` Signed-off-by: Harald Albers --- contrib/completion/bash/docker | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/contrib/completion/bash/docker b/contrib/completion/bash/docker index 79a82d8b3f..3125470e46 100644 --- a/contrib/completion/bash/docker +++ b/contrib/completion/bash/docker @@ -456,6 +456,18 @@ __docker_is_experimental() { [ "$(__docker_q version -f '{{.Server.Experimental}}')" = "true" ] } +# __docker_daemon_os_is tests whether the currently configured Docker daemon runs +# on the operating system passed in as the first argument. +# It does so by querying the daemon for its OS. The result is cached for the duration +# of one invocation of bash completion so that this function can be used to test for +# several different operating systems without additional costs. +# Known operating systems: linux, windows. +__docker_daemon_os_is() { + local expected_os="$1" + local actual_os=${daemon_os=$(__docker_q version -f '{{.Server.Os}}')} + [ "$actual_os" = "$expected_os" ] +} + # __docker_pos_first_nonflag finds the position of the first word that is neither # option nor an option's argument. If there are options that require arguments, # you should pass a glob describing those options, e.g. "--option1|-o|--option2" @@ -1401,6 +1413,13 @@ _docker_container_run() { --volume -v --workdir -w " + __docker_daemon_os_is windows && options_with_args+=" + --cpu-count + --cpu-percent + --credentialspec + --io-maxbandwidth + --io-maxiops + " local boolean_options=" --disable-content-trust=false @@ -4146,7 +4165,7 @@ _docker() { --tlskey " - local host config + local host config daemon_os COMPREPLY=() local cur prev words cword