Prompt is fixed. Now it shows git branch, exit status, bg jobs and time.
This commit is contained in:
243
config/.bashrc
243
config/.bashrc
@@ -9,30 +9,30 @@
|
|||||||
|
|
||||||
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||||
#
|
#
|
||||||
# Source global definitions
|
# Source global definitions
|
||||||
#
|
#
|
||||||
if [ -f /etc/bashrc ]; then
|
if [ -f /etc/bashrc ]; then
|
||||||
. /etc/bashrc
|
. /etc/bashrc
|
||||||
else
|
else
|
||||||
if ! shopt -q login_shell ; then # We're not a login shell
|
if ! shopt -q login_shell ; then # We're not a login shell
|
||||||
for i in /etc/profile.d/*.sh; do
|
for i in /etc/profile.d/*.sh; do
|
||||||
if [ -r "$i" ]; then
|
if [ -r "$i" ]; then
|
||||||
if [ "$PS1" ]; then
|
if [ "$PS1" ]; then
|
||||||
. $i
|
. $i
|
||||||
else
|
else
|
||||||
. $i &>/dev/null
|
. $i &>/dev/null
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
unset i
|
unset i
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
umask 002
|
umask 002
|
||||||
|
|
||||||
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||||
#
|
#
|
||||||
# Find out system details.
|
# Find out system details.
|
||||||
#
|
#
|
||||||
os=`uname -o` #GNU/Linux AIX Solaris
|
os=`uname -o` #GNU/Linux AIX Solaris
|
||||||
cpu=`uname -p` #x86_64 powerpc sparc
|
cpu=`uname -p` #x86_64 powerpc sparc
|
||||||
@@ -43,99 +43,134 @@ hostnm=`hostname`
|
|||||||
|
|
||||||
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||||
#
|
#
|
||||||
# Terminal colors.
|
# Terminal colors if interactive
|
||||||
#
|
#
|
||||||
if [[ $- == *i* ]]; then
|
if [ -n "$PS1" ]; then
|
||||||
#
|
#
|
||||||
# If there is no terminal info in the system for current terminal but there is
|
# If there is no terminal info in the system for current terminal but there is
|
||||||
# one in local terminfo then use it.
|
# one in local terminfo then use it.
|
||||||
#
|
#
|
||||||
/bin/tput -T $TERM longname 2>/dev/null >/dev/null
|
tput -T $TERM longname 2>/dev/null >/dev/null
|
||||||
if [[ $? -ne 0 && -f $HOME/.terminfo/$kernel/${TERM:0:1}/$TERM ]]; then
|
if [ "$?" -ne "0" ] && [ -f $HOME/.terminfo/$kernel/${TERM:0:1}/$TERM ]; then
|
||||||
export TERMINFO=$HOME/.terminfo/$kernel;
|
export TERMINFO=$HOME/.terminfo/$kernel;
|
||||||
fi
|
fi
|
||||||
|
#
|
||||||
###
|
# Number of colors and standard colors.
|
||||||
# Colors
|
#
|
||||||
###
|
c_num=$(tput colors)
|
||||||
# reset terminal colors
|
|
||||||
c_reset="$(tput sgr0)"
|
|
||||||
# regular foreground
|
# regular foreground
|
||||||
crf_red=$(tput setaf 1)
|
c_red=$(tput setaf 1)
|
||||||
crf_green=$(tput setaf 2)
|
c_green=$(tput setaf 2)
|
||||||
crf_orange=$(tput setaf 3)
|
c_orange=$(tput setaf 3)
|
||||||
crf_blue=$(tput setaf 4)
|
c_blue=$(tput setaf 4)
|
||||||
crf_pink=$(tput setaf 5)
|
c_pink=$(tput setaf 5)
|
||||||
crf_cyan=$(tput setaf 6)
|
c_cyan=$(tput setaf 6)
|
||||||
crf_white=$(tput setaf 7)
|
c_white=$(tput setaf 7)
|
||||||
|
c_viol=$(tput setaf 12)
|
||||||
# bold foreground
|
# bold foreground
|
||||||
cbf_red=$(tput bold; tput setaf 1)
|
#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.
|
# Load better colors for ls.
|
||||||
#
|
#
|
||||||
if [ -f ~/.dir_colors ]; then
|
if [ $c_num -ge 256 ] && [ -f ~/.dir_colors ]; then
|
||||||
eval $(dircolors ~/.dir_colors)
|
eval $(dircolors ~/.dir_colors)
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||||
#
|
#
|
||||||
# Prompt.
|
# Prompt if interactive
|
||||||
#
|
#
|
||||||
if [[ "$PS1" ]]; then
|
if [ -n "$PS1" ]; then
|
||||||
export PROMPT_COMMAND=__prompt_command
|
#
|
||||||
|
# Set better colors if available.
|
||||||
|
#
|
||||||
|
if [ $c_num -ge 256 ]; then
|
||||||
|
c_reset="$(tput sgr0)"
|
||||||
|
c_user="$c_green"
|
||||||
|
c_cwd="$c_viol"
|
||||||
|
c_time="$c_pink"
|
||||||
|
c_branch="$c_cyan"
|
||||||
|
c_exit="$c_red"
|
||||||
|
c_jobs="$c_orange"
|
||||||
|
else
|
||||||
|
c_reset="$(tput sgr0)"
|
||||||
|
c_user="$c_green"
|
||||||
|
c_cwd="$c_viol"
|
||||||
|
c_time="$c_pink"
|
||||||
|
c_branch="$c_cyan"
|
||||||
|
c_exit="$c_red"
|
||||||
|
c_jobs="$c_orange"
|
||||||
|
fi
|
||||||
|
|
||||||
|
[ -n "$(which svn)" ] && prompt_check_svn=true
|
||||||
|
[ -n "$(which git)" ] && prompt_check_git=true
|
||||||
|
|
||||||
|
#
|
||||||
|
# Colors should be set here and surrounded with \[\]otherwise bash fails to
|
||||||
|
# calculate prompt length. The text is set through PROMPT_COMMAND
|
||||||
|
PS1="\[$c_user\]\u@\h: \[$c_cwd\]\w" # username@host: working_dir
|
||||||
|
PS1+="\[$c_branch\]\$git_text" # git branch
|
||||||
|
PS1+="\[$c_branch\]\$svn_text" # svn revision
|
||||||
|
PS1+="\[$c_exit\]\$exit_text" # exit status of last command
|
||||||
|
PS1+="\[$c_jobs\]\$jobs_text" # background/suspended jobs
|
||||||
|
PS1+=" \[$c_time\]\t" # time
|
||||||
|
PS1+="\[$c_reset\]\$ " # reset colors and print $
|
||||||
|
|
||||||
|
export PROMPT_COMMAND="__prompt_command; $PROMPT_COMMAND"
|
||||||
function __prompt_command()
|
function __prompt_command()
|
||||||
{
|
{
|
||||||
local es=$?
|
#
|
||||||
if [ $es -eq 0 ]; then
|
# get exit code before any command is run.
|
||||||
local exit_code_color=$crf_green
|
# TODO: doesn't work on pi.
|
||||||
else
|
#
|
||||||
local exit_code_color=$crf_red
|
local exit_code="$?"
|
||||||
fi
|
prompt_extra=""
|
||||||
|
#
|
||||||
local git_branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null | tr -d ' ')
|
# git branch if exist
|
||||||
local svn_rev=$(svn info . 2> /dev/null | awk -F ':' '/Revision:/ { print $2 }')
|
#
|
||||||
|
if [ -n "$prompt_check_git" ]; then
|
||||||
# PS1="$cbf_blue[$exit_code_color\#$cbf_blue]" # command counter
|
local git_branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null | tr -d ' ')
|
||||||
PS1="$cbf_blue[$cbf_blue$?$cbf_blue]\n" # command counter
|
if [ -n "$git_branch" ]; then
|
||||||
# PS1+=" "
|
git_text="[$git_branch]"
|
||||||
PS1+="$cbf_white\u$crf_blue@$cbf_white\h$cbf_white" # username@host
|
else
|
||||||
# PS1+=":"
|
git_text=""
|
||||||
# PS1+="$crf_green\w" # working dir
|
fi
|
||||||
|
fi
|
||||||
if [ -n "$git_branch" ]; then
|
#
|
||||||
PS1+=" "
|
# svn branch if exist
|
||||||
PS1+="$cbf_blue[${cbf_white}$cbf_orange$git_branch$cbf_blue]"
|
#
|
||||||
fi
|
if [ -n "$prompt_check_svn" ]; then
|
||||||
|
local svn_rev=$(svn info . 2> /dev/null | awk -F ':' '/Revision:/ { print $2 }')
|
||||||
if [ -n "$svn_rev" ]; then
|
if [ -n "$svn_rev" ]; then
|
||||||
PS1+=" "
|
svn_text="[$svn_rev]"
|
||||||
PS1+="$cbf_blue[${cbf_white}$cbf_orange$svn_rev$cbf_blue]"
|
else
|
||||||
fi
|
svn_text=""
|
||||||
|
fi
|
||||||
PS1+=">"
|
fi
|
||||||
|
#
|
||||||
# PS1+="$c_reset\n"
|
# exit code if not zero
|
||||||
|
#
|
||||||
|
if [ "$exit_code" -ne "0" ]; then
|
||||||
|
exit_text="[exit=$exit_code]"
|
||||||
|
else
|
||||||
|
exit_text=""
|
||||||
|
fi
|
||||||
|
#
|
||||||
|
# Info about jobs.
|
||||||
|
#
|
||||||
|
local jobs_bg=$(jobs -r | wc -l | tr -d ' ')
|
||||||
|
local jobs_stopped=$(jobs -s | wc -l | tr -d ' ')
|
||||||
|
if [ $jobs_bg -gt 0 ] || [ $jobs_stopped -gt 0 ]; then
|
||||||
|
jobs_text="[bg:$jobs_bg,stp:$jobs_stopped]"
|
||||||
|
else
|
||||||
|
jobs_text=""
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
# Turn on checkwinsize
|
||||||
# are we an interactive shell?
|
shopt -s checkwinsize
|
||||||
# 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
|
fi
|
||||||
|
|
||||||
|
|
||||||
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||||
#
|
#
|
||||||
# User specific environment and startup programs
|
# User specific environment and startup programs
|
||||||
@@ -150,24 +185,17 @@ PATH=$MYLOCAL/bin:$PATH
|
|||||||
PATH=$MYSCRIPTS/bin:$PATH
|
PATH=$MYSCRIPTS/bin:$PATH
|
||||||
|
|
||||||
#
|
#
|
||||||
# VIM
|
# VIM
|
||||||
#
|
#
|
||||||
#VIMDIR=/depot/vim-7.3/bin
|
export EDITOR=vim
|
||||||
#VIM=${VIMDIR}/vim
|
|
||||||
#if [ "$kernel" == "Linux" ]; then
|
|
||||||
# alias vi=$VIM
|
|
||||||
# alias vim=$VIM
|
|
||||||
# alias gvim=${VIMDIR}/gvim
|
|
||||||
# alias ctags="/depot/ctag-5.5.4/bin/ctags"
|
|
||||||
#fi
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# GIT
|
# GIT
|
||||||
#
|
#
|
||||||
[ -f $MYSCRIPTS/bash/git-completion.bash ] && . $MYSCRIPTSE/bash/git-completion.bash
|
[ -f $MYSCRIPTS/bash/git-completion.bash ] && . $MYSCRIPTSE/bash/git-completion.bash
|
||||||
|
|
||||||
#
|
#
|
||||||
# GCC
|
# GCC
|
||||||
#
|
#
|
||||||
#if [ -e /depot/gcc-4.7.2/bin ]; then
|
#if [ -e /depot/gcc-4.7.2/bin ]; then
|
||||||
# PATH=/depot/gcc-4.7.2/bin:$PATH
|
# PATH=/depot/gcc-4.7.2/bin:$PATH
|
||||||
@@ -181,18 +209,18 @@ PATH=$MYSCRIPTS/bin:$PATH
|
|||||||
#fi
|
#fi
|
||||||
|
|
||||||
#
|
#
|
||||||
# GDB
|
# GDB
|
||||||
#
|
#
|
||||||
#prepath /depot/gdb-7.5.1/bin
|
#prepath /depot/gdb-7.5.1/bin
|
||||||
|
|
||||||
#
|
#
|
||||||
# VTune Amplifier
|
# VTune Amplifier
|
||||||
#
|
#
|
||||||
#export INTEL_LICENSE_FILE=28518@us01-lic10:28518@us01-lic11:28518@us01-lic12:28518@tyndall
|
#export INTEL_LICENSE_FILE=28518@us01-lic10:28518@us01-lic11:28518@us01-lic12:28518@tyndall
|
||||||
#alias vtune=/depot/vtune_amplifier_xe_2013_update5/bin64/amplxe-gui
|
#alias vtune=/depot/vtune_amplifier_xe_2013_update5/bin64/amplxe-gui
|
||||||
|
|
||||||
#
|
#
|
||||||
# PURIFY and all.
|
# PURIFY and all.
|
||||||
#
|
#
|
||||||
#postpath /depot/coverity/swat/bin
|
#postpath /depot/coverity/swat/bin
|
||||||
#export RSU_TEMPLATE2_INI=/depot/pure/templates2.ini
|
#export RSU_TEMPLATE2_INI=/depot/pure/templates2.ini
|
||||||
@@ -204,15 +232,16 @@ PATH=$MYSCRIPTS/bin:$PATH
|
|||||||
#alias purecov="/depot/swe/a2007.12/bin/purecov"
|
#alias purecov="/depot/swe/a2007.12/bin/purecov"
|
||||||
#alias quantify"/depot/swe/a2007.12/bin/quantify"
|
#alias quantify"/depot/swe/a2007.12/bin/quantify"
|
||||||
|
|
||||||
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
|
||||||
#
|
#
|
||||||
# Run local settings.
|
# Make sure to export PATH
|
||||||
#
|
#
|
||||||
[ -f $PWD/.bashrc.local ] && . $PWD/.bashrc.local
|
export PATH
|
||||||
|
export HISTFILESIZE=5000 # Store 5000 commands in history
|
||||||
|
export HISTCONTROL=ignoredups # Don't put duplicate lines in the history.
|
||||||
|
|
||||||
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||||
#
|
#
|
||||||
# set alias
|
# Aliases
|
||||||
#
|
#
|
||||||
if [ $kernel == AIX ]; then
|
if [ $kernel == AIX ]; then
|
||||||
alias l='ls -a'
|
alias l='ls -a'
|
||||||
@@ -229,11 +258,9 @@ else
|
|||||||
fi
|
fi
|
||||||
alias cgrep="grep --include \*.cpp --include \*.h --include \*.c"
|
alias cgrep="grep --include \*.cpp --include \*.h --include \*.c"
|
||||||
|
|
||||||
|
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||||
#
|
#
|
||||||
# Make sure to export PATH
|
# Run local settings.
|
||||||
#
|
#
|
||||||
export PATH
|
[ -f $PWD/.bashrc.local ] && . $PWD/.bashrc.local
|
||||||
#export LM_LICENSE_FILE
|
|
||||||
export HISTFILESIZE=5000 # Store 5000 commands in history
|
|
||||||
export HISTCONTROL=ignoredups # Don't put duplicate lines in the history.
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user