Last active
September 13, 2016 09:33
-
-
Save fun4jimmy/dd850ee61fc4a68c16bcd0ee7138c483 to your computer and use it in GitHub Desktop.
.bashrc to configure a coloured bash prompt with current source control branch information if any.
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
# some aliases to mimic windows command prompt directory changes | |
alias c:="cd /mnt/c" | |
alias d:="cd /mnt/d" |
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
# We have to surround every colour with \[ and \] so bash doesn't include them when counting | |
# how long the current line is. Without the escaped characters line wrapping breaks. | |
# Normal Colors | |
black='\[\e[0;30m\]' # Black | |
red='\[\e[0;31m\]' # Red | |
green='\[\e[0;32m\]' # Green | |
yellow='\[\e[0;33m\]' # Yellow | |
blue='\[\e[0;34m\]' # Blue | |
purple='\[\e[0;35m\]' # Purple | |
cyan='\[\e[0;36m\]' # Cyan | |
white='\[\e[0;37m\]' # White | |
# Bold | |
bold_black='\[\e[1;30m\]' # Black | |
bold_red='\[\e[1;31m\]' # Red | |
bold_green='\[\e[1;32m\]' # Green | |
bold_yellow='\[\e[1;33m\]' # Yellow | |
bold_blue='\[\e[1;34m\]' # Blue | |
bold_purple='\[\e[1;35m\]' # Purple | |
bold_cyan='\[\e[1;36m\]' # Cyan | |
bold_white='\[\e[1;37m\]' # White | |
# Background | |
back_black='\[\e[40m\]' # Black | |
back_red='\[\e[41m\]' # Red | |
back_green='\[\e[42m\]' # Green | |
back_yellow='\[\e[43m\]' # Yellow | |
back_blue='\[\e[44m\]' # Blue | |
back_purple='\[\e[45m\]' # Purple | |
back_cyan='\[\e[46m\]' # Cyan | |
back_white='\[\e[47m\]' # White | |
clear_colour='\[\e[m\]' # Color Reset | |
# prints the name of the current git or mercurial branch if any | |
scm_branch() { | |
# git branch lists all branches with a * next to the name of the current so we have to use sed to strip the other branches | |
branch=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'` | |
# use double [ so we don't need to quote the $branch variable | |
# -z tests for an empty string | |
if [[ -z $branch ]]; then | |
branch=`hg branch 2> /dev/null` | |
fi | |
# -n tests for a non empty string | |
if [[ -n $branch ]]; then | |
echo -e "[${branch}]" | |
fi | |
} | |
export PS1="$green\u@\h$clear_colour:$cyan\W${yellow}\$(scm_branch)$clear_colour\$ " | |
if [ -f $HOME/.aliases ]; then | |
source $HOME/.aliases | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment