Skip to content

Instantly share code, notes, and snippets.

@Borales
Created April 21, 2016 21:52
Show Gist options
  • Save Borales/ca47fa5f29371a59eb53fea4b12eba1a to your computer and use it in GitHub Desktop.
Save Borales/ca47fa5f29371a59eb53fea4b12eba1a to your computer and use it in GitHub Desktop.
Docker-machine and Git branch in the bash prompt
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$ "
@Borales
Copy link
Author

Borales commented Apr 21, 2016

screen shot 2016-04-21 at 23 53 04

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment