Last active
November 17, 2016 22:09
-
-
Save petehalverson/41804d5260099621dff3eca694242fd1 to your computer and use it in GitHub Desktop.
Git / Docker environment bash prompt
This file contains 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
# 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