Skip to content

Instantly share code, notes, and snippets.

@toolness
Created September 15, 2016 14:23
Show Gist options
  • Save toolness/29954fffc9cb055a083e8cb8382c13c1 to your computer and use it in GitHub Desktop.
Save toolness/29954fffc9cb055a083e8cb8382c13c1 to your computer and use it in GitHub Desktop.
Bash script to add git branch and docker machine info to prompt
#! /bin/bash
# Most of this is taken from:
#
# https://coderwall.com/p/fasnya/add-git-branch-name-to-bash-prompt
#
# Just modified it to also include the current docker machine being
# used, if any.
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
show_docker_machine_name() {
if [ -n "${DOCKER_MACHINE_NAME}" ]
then
echo " (${DOCKER_MACHINE_NAME})"
fi
}
export PS1="\u@\h \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[35m\]\$(show_docker_machine_name)\[\033[00m\] $ "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment