Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
}
@ghost

This comment has been minimized.

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
You can’t perform that action at this time.