From b881eceec8054d3dccef959d32460163c1a81f2d Mon Sep 17 00:00:00 2001 From: Harald Albers Date: Tue, 21 Feb 2017 11:12:23 +0100 Subject: [PATCH 1/2] Add bash completion for drivers Signed-off-by: Harald Albers --- contrib/completion/bash/docker-machine.bash | 22 ++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/contrib/completion/bash/docker-machine.bash b/contrib/completion/bash/docker-machine.bash index a1ed9f87..82bd6f49 100644 --- a/contrib/completion/bash/docker-machine.bash +++ b/contrib/completion/bash/docker-machine.bash @@ -31,8 +31,28 @@ _docker_machine_config() { } _docker_machine_create() { + case "${prev}" in + --driver|-d) + COMPREPLY=($(compgen -W " + amazonec2 + azure + digitalocean + exoscale + generic + google + hyperv + openstack + rackspace + softlayer + virtualbox + vmwarefusion + vmwarevcloudair + vmwarevsphere" -- "${cur}")) + return + ;; + esac # cheating, b/c there are approximately one zillion options to create - COMPREPLY=($(compgen -W "$(docker-machine create --help | grep '^ -' | sed 's/^ //; s/[^a-z0-9-].*$//')" -- "${cur}")) + COMPREPLY=($(compgen -W "$(docker-machine create --help | grep '^ -' | sed 's/^ //; s/[^a-z0-9-].*$//') --help" -- "${cur}")) } _docker_machine_env() { From 3461a1a579fc40813fd6f484e49c0578fd980a92 Mon Sep 17 00:00:00 2001 From: Harald Albers Date: Tue, 21 Feb 2017 12:17:18 +0100 Subject: [PATCH 2/2] Add bash completion for driver specific options Signed-off-by: Harald Albers --- contrib/completion/bash/docker-machine.bash | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/contrib/completion/bash/docker-machine.bash b/contrib/completion/bash/docker-machine.bash index 82bd6f49..8f9d2dc8 100644 --- a/contrib/completion/bash/docker-machine.bash +++ b/contrib/completion/bash/docker-machine.bash @@ -14,6 +14,16 @@ # . ~/.docker-machine-completion.sh # +_docker_machine_value_of_option() { + local pattern="$1" + for (( i=2; i < ${cword}; ++i)); do + if [[ ${words[$i]} =~ ^($pattern)$ ]] ; then + echo ${words[$i + 1]} + break + fi + done +} + _docker_machine_active() { if [[ "${cur}" == -* ]]; then COMPREPLY=($(compgen -W "--help" -- "${cur}")) @@ -51,8 +61,14 @@ _docker_machine_create() { return ;; esac - # cheating, b/c there are approximately one zillion options to create - COMPREPLY=($(compgen -W "$(docker-machine create --help | grep '^ -' | sed 's/^ //; s/[^a-z0-9-].*$//') --help" -- "${cur}")) + + # driver specific options are only included in help output if --driver is given, + # so we have to pass that option when calling docker-machine to harvest options. + local driver="$(_docker_machine_value_of_option '--driver|-d')" + local parsed_options="$(docker-machine 2>/dev/null create ${driver:+--driver $driver} --help | grep '^ -' | sed 's/^ //; s/[^a-z0-9-].*$//')" + if [[ ${cur} == -* ]]; then + COMPREPLY=($(compgen -W "${parsed_options} -d --help" -- "${cur}")) + fi } _docker_machine_env() {