Skip to content

Instantly share code, notes, and snippets.

@aburnett
Created October 16, 2015 13:40
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aburnett/1165239cd2673a43579c to your computer and use it in GitHub Desktop.
Save aburnett/1165239cd2673a43579c to your computer and use it in GitHub Desktop.
Cheesy method to show currently active docker machine in PS1
#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
}
Copy link

ghost commented Sep 30, 2016

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 (!!!).

EMOJI=<your character... can't seem to make a comment with it in it>
__active_machine() {
    FORMAT=$1
    if [ -n "$DOCKER_HOST" ] ; then
      printf "$FORMAT" "$DOCKER_MACHINE_NAME" "$EMOJI"
    fi
}

PS1='\n\[\e[1;30m\][$$:$PPID - \j:\!\[\e[1;30m\]]\[\e[0;36m\] \T \[\e[1;30m\][\[\e[1;34m\]\u@\H\[\e[1;30m\]:\[\e[0;37m\]${SSH_TTY:-o} \[\e[0;32m\]+${SHLVL}\[\e[1;30m\]] $(__active_machine "%s %s ") \[\e[1;37m\]\w\[\e[0;37m\] \n\$ '

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment