aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/docker-machine
diff options
context:
space:
mode:
authorToby Vincent <tobyv13@gmail.com>2021-07-11 18:20:46 -0500
committerToby Vincent <tobyv13@gmail.com>2021-07-11 18:20:46 -0500
commit9df7551de33d318fefc28db66d84db3cf0d49ac9 (patch)
treea417acfd4145adaeec3c2812b070aa10d1c493cb /docker-machine
parent2499ac071151640d0bf0f1bba53ff1df1cd0f604 (diff)
feat: added docker machine use wrapper
Diffstat (limited to 'docker-machine')
-rw-r--r--docker-machine/wrapper.sh56
1 files changed, 56 insertions, 0 deletions
diff --git a/docker-machine/wrapper.sh b/docker-machine/wrapper.sh
new file mode 100644
index 0000000..89aabfa
--- /dev/null
+++ b/docker-machine/wrapper.sh
@@ -0,0 +1,56 @@
+#
+# 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
+ command docker-machine "$@"
+ fi
+}
+
+if [[ ${DOCKER_MACHINE_WRAPPED} = true ]]; then
+ alias docker-machine=__docker_machine_wrapper
+fi