1
0
mirror of https://github.com/docker/docs.git synced 2026-11-06 12:54:24 +03:00
Files
docs/contrib/completion/bash/docker-machine-wrapper.bash
David M. Lee 7180ddca87 Adding bash completion and helper scripts
This patch adds some bash helper scripts.

 * docker-machine.bash - command completion for docker-machine
 * docker-machine-prompt.bash - function for putting the active machine
   name in PS1
 * docker-machine-wrapper.bash - function wrapper adding an `use`
   command that runs `eval $(docker-machine env whatever)` in the
   current shell.

Signed-off-by: David M. Lee <dlee@respoke.io>
2015-10-22 15:34:42 -05:00

57 lines
1.5 KiB
Bash

#
# Function wrapper to docker-machine that adds a use subcommand.
#
# The use subcommand runs `eval "$(docker-machine env [args])"`, which is a lot
# less typing.
#
# To enable:
# 1a. Copy this file somewhere and source it in your .bashrc
# source /some/where/docker-machine-wrapper.bash
# 1b. Alternatively, just copy this file into into /etc/bash_completion.d
#
# Configuration:
#
# DOCKER_MACHINE_WRAPPED
# When set to a value other than true, this will disable the alias wrapper
# alias for docker-machine. This is useful if you don't want the wrapper,
# but it is installed by default by your installation.
#
: ${DOCKER_MACHINE_WRAPPED:=true}
__docker-machine-wrapper () {
if [[ "$1" == use ]]; then
# Special use wrapper
shift 1
case "$1" in
-h|--help|"")
cat <<EOF
Usage: docker-machine use [OPTIONS] [arg...]
Evaluate the commands to set up the environment for the Docker client
Description:
Argument is a machine name.
Options:
--swarm Display the Swarm config instead of the Docker daemon
--unset, -u Unset variables instead of setting them
EOF
;;
*)
eval "$(docker-machine env "$@")"
echo "Active machine: ${DOCKER_MACHINE_NAME}"
;;
esac
else
# Just call the actual docker-machine app
$(which docker-machine) "$@"
fi
}
if [[ ${DOCKER_MACHINE_WRAPPED} = true ]]; then
alias docker-machine=__docker-machine-wrapper
fi