Created
April 21, 2016 21:52
-
-
Save Borales/ca47fa5f29371a59eb53fea4b12eba1a to your computer and use it in GitHub Desktop.
Docker-machine and Git branch in the 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
parse_git_branch() { | |
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ on \"\1\" branch/' | |
} | |
__docker_machine_ps1 () { | |
local format=${1:- [%s]} | |
if test ${DOCKER_MACHINE_NAME}; then | |
local status | |
if test ${DOCKER_MACHINE_PS1_SHOWSTATUS:-false} = true; then | |
status=$(docker-machine status ${DOCKER_MACHINE_NAME}) | |
case ${status} in | |
Running) | |
status=' R' | |
;; | |
Stopping) | |
status=' R->S' | |
;; | |
Starting) | |
status=' S->R' | |
;; | |
Error|Timeout) | |
status=' E' | |
;; | |
*) | |
# Just consider everything elase as 'stopped' | |
status=' S' | |
;; | |
esac | |
fi | |
printf -- "${format}" "${DOCKER_MACHINE_NAME}${status}" | |
fi | |
} | |
export PS1="\u@\h \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\]\$(__docker_machine_ps1 \" \[\e[36m\](\\\"%s\\\" machine)\[\e[m\]\") \n$ " |
Author
Borales
commented
Apr 21, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment