Last active
January 11, 2018 09:13
-
-
Save sphinxid/60e11d7c5557c450cda7983a27faef9d to your computer and use it in GitHub Desktop.
sphinx bashrc - Colorful BASHrc config with github branch support displayed.
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
#git branch | |
# __git_branch='`git branch 2> /dev/null | grep -e ^* | sed -E s/^\\\\\*\ \(.+\)$/\(\\\\\1\)\ /`' | |
# "\[\033[36m\]\u\[\033[m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\$ " | |
function parse_git_dirty { | |
echo -n $(git status 2>/dev/null | awk -v out=$1 -v std="dirty" '{ if ($0=="# Changes to be committed:") std = "uncommited"; last=$0 } END{ if(last!="" && last!="nothing to commit (working directory clean)") { if(out!="") print out; else print std } }') | |
} | |
function parse_git_branch { | |
echo -n $(git branch --no-color 2>/dev/null | awk -v out=$1 '/^*/ { if(out=="") print $2; else print out}') | |
} | |
function parse_git_remote { | |
echo -n $(git status 2>/dev/null | awk -v out=$1 '/# Your branch is / { if(out=="") print $5; else print out }') | |
} | |
if [ -d .git ] | |
then | |
read hd <.git/HEAD | |
[[ $hd < g ]] && hd="${hd::7}" || hd="${hd##*/}" | |
fi | |
# export PS1="\`if [ \$? = 0 ]; then echo \[\e[33m\]^_^\[\e[0m\]; else echo \[\e[31m\]O_O\[\e[0m\]; fi\` \[\033[36m\]\u\[\033[m\]\[\e[1;31m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\[\033[37;1m\]\$\[\033[m\] " | |
# export PS1="\`if [ \$? = 0 ]; then echo \[\e[33m\]^_^\[\e[0m\]; else echo \[\e[31m\]O_O\[\e[0m\]; fi\` \[\033[36m\]\u\[\033[m\]\[\e[1;31m\]@\[\033[32m\]\h:\[\033[33;1m\]\w\[\033[m\]\[\033[37;1m\]\$\[\033[m\] \e[36m $parse_git_branch \[\e[m\]" | |
# .bashrc loaded by .profile | |
# [[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile | |
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function* | |
function myBashPrompt { | |
local __userandhost="\`if [ \$? = 0 ]; then echo \[\e[33m\]^_^\[\e[0m\]; else echo \[\e[31m\]O_O\[\e[0m\]; fi\` \[\033[36m\]\u\[\033[m\]\[\e[1;31m\]@\[\033[32m\]\h:" | |
local __pwd="\[\033[33;1m\]\w" | |
local __gitbranch_color="\[\033[31m\]" | |
local __gitbranch='`git branch 2> /dev/null | grep -e ^* | sed -E s/^\\\\\*\ \(.+\)$/\(\\\\\1\)\ /`' | |
local __prompt_tail="\[\033[34m\]$" | |
local __shellcolor="\[\033[00m\]" | |
export PS1="$__userandhost$__pwd $__gitbranch_color$__gitbranch$__prompt_tail$__shellcolor " | |
} | |
myBashPrompt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment