Last active
July 31, 2018 13:17
-
-
Save Pitt-Pauly/8e0943496b733f18d86de36118131f04 to your computer and use it in GitHub Desktop.
My pretty prompt!
This file contains hidden or 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
#!/bin/bash | |
# | |
# DESCRIPTION: | |
# | |
# Set the bash prompt according to: | |
# * the active virtualenv | |
# * the branch of the current git/mercurial repository | |
# * the return value of the previous command | |
# * the fact you just came from Windows and are used to having newlines in | |
# your prompts. | |
# | |
# USAGE: | |
# | |
# 1. Save this file as ~/.bash_prompt | |
# 2. Add the following line to the end of your ~/.bashrc or ~/.bash_profile: | |
# . ~/.bash_prompt | |
# | |
# LINEAGE: | |
# Based on work by Laila Atrmouh and Jaques-Olivier Dordonne | |
# Based on work by woods - https://gist.github.com/31967 | |
# The various escape codes that we can use to color our prompt. | |
RED="\[\033[0;31m\]" | |
YELLOW="\[\033[1;33m\]" | |
GREEN="\[\033[0;32m\]" | |
BLUE="\[\033[1;34m\]" | |
PURPLE="\[\033[0;35m\]" | |
LIGHT_RED="\[\033[1;31m\]" | |
LIGHT_GREEN="\[\033[1;32m\]" | |
WHITE="\[\033[1;37m\]" | |
LIGHT_GRAY="\[\033[0;37m\]" | |
COLOR_NONE="\[\e[0m\]" | |
if [ -f /etc/bash_completion ]; then | |
source /etc/bash_completion | |
fi | |
__has_parent_dir () { | |
# Utility function so we can test for things like .git/.hg without firing up a | |
# separate process | |
test -d "$1" && return 0; | |
current="." | |
while [ ! "$current" -ef "$current/.." ]; do | |
if [ -d "$current/$1" ]; then | |
return 0; | |
fi | |
current="$current/.."; | |
done | |
return 1; | |
} | |
__vcs_name() { | |
if [ -d .svn ]; then | |
echo "${BLACK}-[${YELLOW}svn${BLACK}]"; | |
elif __has_parent_dir ".git"; then | |
echo "${BLACK}-[${YELLOW}$(__git_ps1 'git %s')${BLACK}]"; | |
elif __has_parent_dir ".hg"; then | |
echo "${BLACK}-[${YELLOW}hg $(hg branch)${BLACK}]" | |
fi | |
} | |
BLACK=$(tput -Txterm setaf 0) | |
RED=$(tput -Txterm setaf 1) | |
GREEN=$(tput -Txterm setaf 2) | |
YELLOW=$(tput -Txterm setaf 3) | |
DK_BLUE=$(tput -Txterm setaf 4) | |
PINK=$(tput -Txterm setaf 5) | |
LT_BLUE=$(tput -Txterm setaf 6) | |
BOLD=$(tput -Txterm bold) | |
RESET=$(tput -Txterm sgr0) | |
# Determine active Python virtualenv details. | |
function set_virtualenv () { | |
if test -z "$VIRTUAL_ENV" ; then | |
PYTHON_VIRTUALENV="" | |
else | |
PYTHON_VIRTUALENV="-[${LT_BLUE}`basename \"$VIRTUAL_ENV\"`${BLACK}]" | |
fi | |
} | |
# Set the full bash prompt. | |
function set_bash_prompt () { | |
# Set the PYTHON_VIRTUALENV variable. | |
set_virtualenv | |
# Set the BRANCH variable. | |
#set_git_branch | |
# Set the bash prompt variable. | |
#PS1=" | |
#${PYTHON_VIRTUALENV}${GREEN}\u@\h${COLOR_NONE}:${YELLOW}\w${COLOR_NONE}${BRANCH} | |
#${PROMPT_SYMBOL} " | |
PS1='\n\[$BOLD\]\[$BLACK\][\[$DK_BLUE\]\@\[$BLACK\]]${PYTHON_VIRTUALENV}-[\[$GREEN\]\u@\h\[$BLACK\]]-[\[$PINK\]\w\[$BLACK\]]\[$YELLOW\]$(__vcs_name)\[$YELLOW\]\[$RESET\]\n\[$RESET\]\$ ' | |
} | |
# Tell bash to execute this function just before displaying its prompt. | |
PROMPT_COMMAND=set_bash_prompt | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment