Skip to content

Instantly share code, notes, and snippets.

@avoidik
Last active August 14, 2020 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avoidik/6bc7973d0315df294a4eef9c274350af to your computer and use it in GitHub Desktop.
Save avoidik/6bc7973d0315df294a4eef9c274350af to your computer and use it in GitHub Desktop.
git for windows git-prompt.sh to show branch and virtualenv
#!/bin/bash
PROMPT_DIRTRIM=2
RED="\[\033[0;31m\]"
YELLOW="\[\033[1;33m\]"
GREEN="\[\033[0;32m\]"
BLUE="\[\033[0;34m\]"
LIGHT_BLUE="\[\033[1;34m\]"
LIGHT_RED="\[\033[1;31m\]"
LIGHT_GREEN="\[\033[1;32m\]"
WHITE="\[\033[1;37m\]"
DARK_GRAY="\[\033[1;30m\]"
LIGHT_GRAY="\[\033[0;37m\]"
LIGHT_CYAN="\[\033[1;36m\]"
CYAN="\[\033[0;36m\]"
PURPLE="\[\033[0;35m\]"
BROWN="\[\033[0;33m\]"
LIGHT_PURPLE="\[\033[1;35m\]"
BLACK="\[\033[0;30m\]"
COLOR_NONE="\[\033[0m\]"
function set_git_branch () {
this_branch="$(git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/')"
if test -z "$this_branch" ; then
PROMPT_BRANCH=""
else
PROMPT_BRANCH="${YELLOW}${this_branch}${COLOR_NONE} "
fi
}
function set_prompt_symbol () {
if test $1 -eq 0 ; then
PROMPT_SYMBOL="${LIGHT_GREEN}\$${COLOR_NONE} "
else
PROMPT_SYMBOL="${LIGHT_RED}\$${COLOR_NONE} "
fi
}
function set_virtualenv () {
if test -z "$VIRTUAL_ENV" ; then
PROMPT_PYTHON_ENV=""
else
PROMPT_PYTHON_ENV="${LIGHT_BLUE}[$(basename \\"$VIRTUAL_ENV\\")]${COLOR_NONE} "
fi
}
function set_condaenv () {
if test -z "$CONDA_DEFAULT_ENV" ; then
PROMPT_CONDA_ENV=""
else
PROMPT_CONDA_ENV="${LIGHT_CYAN}[${CONDA_DEFAULT_ENV}]${COLOR_NONE} "
fi
}
function set_docker_machine () {
if test -z "$DOCKER_MACHINE_NAME" ; then
PROMPT_DOCKER_MACHINE=""
else
PROMPT_DOCKER_MACHINE="${LIGHT_PURPLE}[${DOCKER_MACHINE_NAME}]${COLOR_NONE} "
fi
}
function set_user_line () {
PROMPT_USER_LINE="$(date '+%T') ${GREEN}\u${COLOR_NONE} "
}
function set_bash_prompt () {
set_prompt_symbol $?
set_user_line
set_virtualenv
set_condaenv
set_git_branch
set_docker_machine
PS1="${PROMPT_USER_LINE}${PROMPT_PYTHON_ENV}${PROMPT_CONDA_ENV}${PROMPT_DOCKER_MACHINE}${WHITE}\w${COLOR_NONE} ${PROMPT_BRANCH}${PROMPT_SYMBOL}"
}
PROMPT_COMMAND=set_bash_prompt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment