Skip to content

Instantly share code, notes, and snippets.

@tomfun
Created July 24, 2017 20:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomfun/e19af3613dd085e80a6a6824c4fd9f8c to your computer and use it in GitHub Desktop.
Save tomfun/e19af3613dd085e80a6a6824c4fd9f8c to your computer and use it in GitHub Desktop.
my colored .bashrc
alias grep='grep --color=auto'
alias ls='ls --color=auto'
#PS1='\[\033[1;36m\]\u\[\033[1;31m\]@\[\033[1;32m\]\h:\[\033[1;35m\]\w\[\033[1;31m\]\$\[\033[0m\] '
git_branch () { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'; }
BRANCH='\033[00;33m$(git_branch)\033[0m'
PSC() { echo -ne "\[\033[${1:-0;38}m\]"; }
PR="1;36" # default color used in prompt is green
if [ "$(id -u)" = 0 ]; then
sudo="1;31" # root is red background
elif [ "$USER" != "${SUDO_USER:-$USER}" ]; then
sudo=93 # not root, not self: red text
else sudo="$PR" # standard user color
fi
PROMPT_COMMAND='[ $? = 0 ] && PS1=${PS1[1]} || PS1=${PS1[2]}'
PSbase="\[\033[00;35m\]\A|$(PSC $sudo)\u\[\033[1;31m\]@\[\033[1;32m\]\h:\[\033[1;35m\]\w $BRANCH"
PS1[1]="$PSbase$(PSC "0;92")\$ $(PSC)"
PS1[2]="$PSbase$(PSC "1;31")\$ $(PSC)"
PS1="${PS1[1]}"
unset sudo PR PSbase
@tomfun
Copy link
Author

tomfun commented Jul 24, 2017

_2017-07-24_22-58-44

@bilalahmad99
Copy link

bilalahmad99 commented Feb 26, 2020

this is good stuff.
one small issue it starts to wrap line when the length of prompt ends. I added a line stty columns 1000 before PS1 to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment