Created
October 16, 2015 13:40
-
-
Save aburnett/1165239cd2673a43579c to your computer and use it in GitHub Desktop.
Cheesy method to show currently active docker machine in PS1
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
#Usage: PS1='[$(__active_machine "{%s} ")\u@\h $] | |
EMOJI=🐳 | |
__active_machine() { | |
FORMAT=$1 | |
if ACTIVE=$(docker-machine active 2>/dev/null); then | |
STATE=$(docker-machine status $ACTIVE) | |
if [ "$STATE" = "Running" ]; then | |
unset STATE | |
IP=$(docker-machine ip $ACTIVE) | |
fi | |
printf "$FORMAT" "$EMOJI $ACTIVE: $STATE$IP" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This does almost as much, but without executing docker-machine (which is pretty slow to run for every prompt...). Just name your docker machines sensibly, e.g. com.domain.sub. I'm using this to essentially tell me that I'm at least referencing a docker host that isn't local, so I should pay attention (!!!).