Last active
February 21, 2020 18:02
-
-
Save dzmitryk/2279ccca073b3ec80b441f2316f31ae4 to your computer and use it in GitHub Desktop.
Shutdown Docker for mac if no containers are running
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
TIMEOUT=$1 | |
LAST_USED_FILE=~/.docker_last_usage | |
docker ps -q > /dev/null 2> /dev/null | |
result=$? | |
if [[ $result -eq 0 && -z $(docker ps -q) && $(cat $LAST_USED_FILE 2> /dev/null) && $(expr $(date +%s) - $(cat $LAST_USED_FILE 2> /dev/null)) -gt $TIMEOUT ]]; then | |
osascript -e 'quit app "Docker"' | |
elif [[ $result -eq 0 && -n $(docker ps -q) ]]; then | |
date +%s > "$LAST_USED_FILE" | |
elif [[ $result -eq 0 && ! -f $LAST_USED_FILE ]]; then | |
date +%s > "$LAST_USED_FILE" | |
elif [[ $result -ne 0 ]]; then | |
rm -f $LAST_USED_FILE | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment