Last active
January 12, 2022 16:20
-
-
Save adamjcooper/90016bca7a775ea6a2f709ce4c384ed0 to your computer and use it in GitHub Desktop.
git prompt setup for mac ~/.bash_profile, with active python virtualenv
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
export BASH_SILENCE_DEPRECATION_WARNING=1 | |
eval "$(/opt/homebrew/bin/brew shellenv)" | |
# --- git command prompt --- | |
# Pre-requisites: | |
# brew install bash-completion | |
if [ -f $(brew --prefix)/etc/bash_completion ]; then | |
. $(brew --prefix)/etc/bash_completion | |
fi | |
source $(brew --prefix)/etc/bash_completion.d/git-completion.bash | |
source $(brew --prefix)/etc/bash_completion.d/git-prompt.sh | |
export GIT_PS1_SHOWDIRTYSTATE=true | |
export GIT_PS1_SHOWUPSTREAM=true | |
export GIT_PS1_SHOWCOLORHINTS=true #this only works when using PROMPT_COMMAND instead of PS1 | |
export VIRTUAL_ENV_DISABLE_PROMPT=1 | |
#This is a function call: __git_ps1(pre, post) | |
#pre is the part of the prompt before the branch status | |
#post is the part of the prompt after the branch status | |
#See https://github.com/git/git/blob/e5da8655b23737a8449868e1d99973a8d0e25fe3/contrib/completion/git-prompt.sh#L23 | |
GREEN='\e[38;5;64m' | |
YELLOW='\e[38;5;11m' | |
DARK_GRAY='\e[90m' | |
WORKING_DIRECTORY='\w' | |
RESET_COLORS='\e[0m' | |
# Create an env var with the value of the current python virtualenv | |
set_active_venv() { | |
export ACTIVE_VENV="" | |
if [ "$VIRTUAL_ENV" != "" ]; then | |
export ACTIVE_VENV="$DARK_GRAY[`basename \"$VIRTUAL_ENV\"`]$RESET_COLORS" | |
fi | |
} | |
# Update prompt to show git status and, when present, current python virtualenv | |
export PROMPT_COMMAND='set_active_venv; __git_ps1 "\n$GREEN$WORKING_DIRECTORY$RESET_COLORS" " $ACTIVE_VENV\nλ "' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment