Skip to content

Instantly share code, notes, and snippets.

@petehalverson
Last active November 17, 2016 22:09
Show Gist options
  • Save petehalverson/41804d5260099621dff3eca694242fd1 to your computer and use it in GitHub Desktop.
Save petehalverson/41804d5260099621dff3eca694242fd1 to your computer and use it in GitHub Desktop.
Git / Docker environment bash prompt
# add to .bashrc, .bash_profile, ~/.profile
git_docker_env() {
branch=
gitlabel="git."
dockerlabel="docker."
sep="| "
if [ -d .git ]; then
status=$(git status 2> /dev/null)
branch="$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/')"
if [[ $( echo $status | grep "branch is ahead") ]]; then
branch="$branch*"
fi
if [[ $( echo $status | grep "working tree clean") ]]; then
branch="$gitlabel\033[32m$branch\033[m"
else
branch="$gitlabel\033[93m$branch\033[m";
fi
fi
if ! [ -z "$DOCKER_MACHINE_NAME" ]; then dockenv="$dockerlabel\033[32m${DOCKER_MACHINE_NAME}\033[m"; fi
if ! [ -z "$dockenv" ] && ! [ -z "$branch" ]; then dockenv=" $sep$dockenv"; fi
if ! [ -z "$branch$dockenv" ]; then echo -e " $sep$branch$dockenv"; fi
}
PS1="\h:\W\$(git_docker_env) $ "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment