Git branch is added to bash prompt + colors are configured.

This commit is contained in:
Vahagn Khachatryan
2016-06-03 13:45:22 -04:00
parent cd33a61a87
commit 5053c86daa
2 changed files with 391 additions and 13 deletions

View File

@@ -14,14 +14,6 @@
if [ -f /etc/bashrc ]; then
. /etc/bashrc
else
# are we an interactive shell?
if [ "$PS1" ]; then
PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"'
# Turn on checkwinsize
shopt -s checkwinsize
[ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "
fi
if ! shopt -q login_shell ; then # We're not a login shell
for i in /etc/profile.d/*.sh; do
if [ -r "$i" ]; then
@@ -49,15 +41,101 @@ kversion=`uname -v`
krelease=`uname -r`
hostnm=`hostname`
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#
# If there is no terminal info in the system for current terminal but there is
# one in local terminfo then use it.
# Terminal colors.
#
/bin/tput -T $TERM longname 2>/dev/null >/dev/null
if [[ $? -ne 0 && -f $HOME/.terminfo/$kernel/${TERM:0:1}/$TERM ]]; then
export TERMINFO=$HOME/.terminfo/$kernel;
if [[ $- == *i* ]]; then
#
# If there is no terminal info in the system for current terminal but there is
# one in local terminfo then use it.
#
/bin/tput -T $TERM longname 2>/dev/null >/dev/null
if [[ $? -ne 0 && -f $HOME/.terminfo/$kernel/${TERM:0:1}/$TERM ]]; then
export TERMINFO=$HOME/.terminfo/$kernel;
fi
###
# Colors
###
# reset terminal colors
c_reset="$(tput sgr0)"
# regular foreground
crf_red=$(tput setaf 1)
crf_green=$(tput setaf 2)
crf_orange=$(tput setaf 3)
crf_blue=$(tput setaf 4)
crf_pink=$(tput setaf 5)
crf_cyan=$(tput setaf 6)
crf_white=$(tput setaf 7)
# bold foreground
cbf_red=$(tput bold; tput setaf 1)
cbf_green=$(tput bold; tput setaf 2)
cbf_orange=$(tput bold; tput setaf 3)
cbf_blue=$(tput bold; tput setaf 4)
cbf_pink=$(tput bold; tput setaf 5)
cbf_cyan=$(tput bold; tput setaf 6)
cbf_white=$(tput bold; tput setaf 7)
#
# Load better colors.
#
if [ -f ~/.dir_colors ]; then
eval $(dircolors ~/.dir_colors)
fi
fi
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#
# Prompt.
#
if [[ "$PS1" ]]; then
export PROMPT_COMMAND=__prompt_command
function __prompt_command()
{
local es=$?
if [ $es -eq 0 ]; then
local exit_code_color=$crf_green
else
local exit_code_color=$crf_red
fi
local git_branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null | tr -d ' ')
local svn_rev=$(svn info . 2> /dev/null | awk -F ':' '/Revision:/ { print $2 }')
# PS1="$cbf_blue[$exit_code_color\#$cbf_blue]" # command counter
PS1="$cbf_blue[$cbf_blue$?$cbf_blue]\n" # command counter
# PS1+=" "
PS1+="$cbf_white\u$crf_blue@$cbf_white\h$cbf_white" # username@host
# PS1+=":"
# PS1+="$crf_green\w" # working dir
if [ -n "$git_branch" ]; then
PS1+=" "
PS1+="$cbf_blue[${cbf_white}$cbf_orange$git_branch$cbf_blue]"
fi
if [ -n "$svn_rev" ]; then
PS1+=" "
PS1+="$cbf_blue[${cbf_white}$cbf_orange$svn_rev$cbf_blue]"
fi
PS1+=">"
# PS1+="$c_reset\n"
}
# are we an interactive shell?
# if [ "$PS1" ]; then
# PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}\007"'
# # Turn on checkwinsize
# shopt -s checkwinsize
# [ "$PS1" = "\\s-\\v\\\$ " ] && PS1="[\u@\h \W]\\$ "
# fi
fi
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
#
# User specific environment and startup programs