diff --git a/utilities/utilities.plugin.zsh b/utilities/utilities.plugin.zsh index 72fb3f2..e6fd8c7 100644 --- a/utilities/utilities.plugin.zsh +++ b/utilities/utilities.plugin.zsh @@ -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 " + 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 . 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