Skip to content

Instantly share code, notes, and snippets.

@Nemo64
Created August 31, 2014 10:59
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 Nemo64/986ff8bf0ddb6a6885d0 to your computer and use it in GitHub Desktop.
Save Nemo64/986ff8bf0ddb6a6885d0 to your computer and use it in GitHub Desktop.
Very dynamic and colorfull .bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files for examples
# Test for an interactive shell. There is no need to set anything
# past this point for scp and rcp, and it's important to refrain from
# outputting anything in those cases.
# If not running interactively, don't do anything!
[[ $- != *i* ]] && return
# Enable history appending instead of overwriting.
shopt -s histappend
if [ "$PS1" ]; then
# git support
if [ -f /usr/lib/git-core/git-sh-prompt ]
then
source /usr/lib/git-core/git-sh-prompt
GIT_PS1_SHOWDIRTYSTATE=true
fi
# fallback if the git prompt does not exist
if ! hash __git_ps1 2> /dev/null
then
alias __git_ps1="git branch 2>/dev/null | grep '*' | sed 's/* \(.*\)/(\1)/'"
fi
# enable colors for some commands
alias ls='ls -G'
alias grep='grep --color=auto'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias ll='ls -alGF' # sometimes exists but sometimes does not
# prepare color schema
# md5 to number can be positive or negative
# number % 4 gives -3 to +3
# that + 33 allows for colors from 30 – 36 which excludes white
USER_NAME=`whoami|md5`
USER_COLOR=$(( 0x${USER_NAME%% *} % 4 + 34 ))
HOST_NAME=`hostname -s|md5`
HOST_COLOR=$(( 0x${HOST_NAME%% *} % 4 + 34 ))
function git_branch_colored {
BRANCH=`__git_ps1`
BRANCH_ONLY=`echo $BRANCH|grep -oE "[a-z0-9_-]+"`
BRANCH_HASH=`echo $BRANCH_ONLY|md5`
BRANCH_COLOR=$(( 0x${BRANCH_HASH%% *} % 4 + 34 ))
echo -e "\033[${BRANCH_COLOR}m${BRANCH}\033[39m"
}
# nice prompt:
USER='\[\033['"$USER_COLOR"'m\]\u\[\033[39m\]'
HOST='\[\033['"$HOST_COLOR"'m\]\h\[\033[39m\]'
DIR='\[\033[34m\]\w\[\033[39m\]'
GIT='$(git_branch_colored)'
export PS1="${USER} ${HOST} ${DIR}${GIT}: "
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment