Make using docker on macOS nicer
This commit is contained in:
parent
c4a91481db
commit
309a8833c8
@ -1,5 +1,7 @@
|
||||
# A collection of various shell utilities.
|
||||
|
||||
autoload colors && colors
|
||||
|
||||
# Detect the type and extract an archive file.
|
||||
extract() {
|
||||
if [ -f $1 ]; then
|
||||
@ -16,9 +18,38 @@ extract() {
|
||||
*.zip) unzip $1 ;;
|
||||
*.Z) uncompress $1 ;;
|
||||
*.7z) 7zr x $1 ;;
|
||||
*) echo "error: unable to extract '$1'" ;;
|
||||
*) echo "$fg[red]error:$reset_color unable to extract '$1'" ;;
|
||||
esac
|
||||
else
|
||||
echo "error: file not found '$1'"
|
||||
echo "$fg[red]error:$reset_color file not found '$1'"
|
||||
fi
|
||||
}
|
||||
|
||||
if which docker-machine &> /dev/null; then
|
||||
# Wrap the docker command to print a message if a docker-machine is not
|
||||
# running, rather than just stating it can not find it's socket.
|
||||
docker() {
|
||||
command docker "$@"
|
||||
if ! docker-machine active &> /dev/null; then
|
||||
echo "$fg[red]error:$reset_color no active host found, run:" \
|
||||
"docker-machine start <machine>"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Wrap the docker-machine command to automatically update the environment.
|
||||
# When a machine is started, set the environment variables provided by
|
||||
# docker-machine env <machine>. When a machine is stopped, unset the same
|
||||
# variables.
|
||||
docker-machine() {
|
||||
command docker-machine "$@"
|
||||
if [ "start" = "$1" ]; then
|
||||
eval `docker-machine env $2`
|
||||
elif [ "stop" = "$1" ]; then
|
||||
unset DOCKER_MACHINE_NAME
|
||||
unset DOCKER_CERT_PATH
|
||||
unset DOCKER_HOST
|
||||
unset DOCKER_TLS_VERIFY
|
||||
fi
|
||||
}
|
||||
fi
|
||||
|
Loading…
x
Reference in New Issue
Block a user