Created
July 24, 2017 20:02
-
-
Save tomfun/e19af3613dd085e80a6a6824c4fd9f8c to your computer and use it in GitHub Desktop.
my colored .bashrc
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
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 |
Author
tomfun
commented
Jul 24, 2017
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