bashrc: prompt revisited
This commit is contained in:
109
config/.bashrc
109
config/.bashrc
@@ -70,23 +70,15 @@ if [ -n "$PS1" ]; then
|
||||
# If there is no terminal info in the system for current terminal but there is
|
||||
# one in local terminfo then use it.
|
||||
#
|
||||
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
|
||||
#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
|
||||
#
|
||||
# Number of colors and standard colors.
|
||||
#
|
||||
c_num=$(tput colors)
|
||||
# regular foreground
|
||||
c_red=$(tput setaf 1)
|
||||
c_green=$(tput setaf 2)
|
||||
c_orange=$(tput setaf 3)
|
||||
c_blue=$(tput setaf 4)
|
||||
c_pink=$(tput setaf 33)
|
||||
c_cyan=$(tput setaf 6)
|
||||
c_white=$(tput setaf 7)
|
||||
c_viol=$(tput setaf 99)
|
||||
#
|
||||
# bold foreground
|
||||
#cbf_red=$(tput bold; tput setaf 1)
|
||||
#
|
||||
@@ -95,6 +87,23 @@ if [ -n "$PS1" ]; then
|
||||
if [ $c_num -ge 256 ] && [ -f ~/.dir_colors ]; then
|
||||
eval $(dircolors ~/.dir_colors)
|
||||
fi
|
||||
|
||||
function term_colors(){
|
||||
for i in {0..15}; do
|
||||
for j in {0..15}; do
|
||||
c=$((i*16+j));
|
||||
printf " $(tput setab $c)%04d" $c;
|
||||
done;
|
||||
printf "$(tput sgr0)\n";
|
||||
done
|
||||
for i in {0..15}; do
|
||||
for j in {0..15}; do
|
||||
c=$((i*16+j));
|
||||
printf " $(tput setaf $c)%04d" $c;
|
||||
done;
|
||||
printf "$(tput sgr0)\n";
|
||||
done
|
||||
}
|
||||
fi
|
||||
|
||||
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
|
||||
@@ -107,38 +116,26 @@ if [ -n "$PS1" ]; then
|
||||
#
|
||||
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"
|
||||
c_user="$(tput setaf 112)" #Green
|
||||
c_cwd="$(tput setaf 99)"
|
||||
c_time="$(tput setaf 33)" #Light blue
|
||||
c_branch="$(tput setaf 138)"
|
||||
c_exit="$(tput setaf 203)" #Red
|
||||
c_jobs="$(tput setaf 220)" #Yellow
|
||||
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"
|
||||
c_user="$(tput setaf 2)" #Green
|
||||
c_cwd="$(tput setaf 7)" #White
|
||||
c_time="$(tput setaf 6)" #Cyan
|
||||
c_branch="$(tput setaf 6)" #Cyan
|
||||
c_exit="$(tput setaf 1)" #Red
|
||||
c_jobs="$(tput setaf 3)" #Yellow
|
||||
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:" # username@host:
|
||||
PS1+="\[$c_time\]\t" # time
|
||||
PS1+=" \[$c_cwd\]\w" # 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_reset\]\$ " # reset colors and print $
|
||||
|
||||
export PROMPT_COMMAND="__prompt_command; $PROMPT_COMMAND"
|
||||
export PROMPT_COMMAND="__prompt_command"
|
||||
function __prompt_command()
|
||||
{
|
||||
#
|
||||
@@ -147,15 +144,16 @@ if [ -n "$PS1" ]; then
|
||||
#
|
||||
local exit_code="$?"
|
||||
prompt_extra=""
|
||||
PS1="\[$c_user\]\u@\h:" # username@host:
|
||||
PS1+="\[$c_time\]\t" # time
|
||||
PS1+=" \[$c_cwd\]\w" # working_dir
|
||||
#
|
||||
# git branch if exist
|
||||
#
|
||||
if [ -n "$prompt_check_git" ]; then
|
||||
local git_branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null | tr -d ' ')
|
||||
if [ -n "$git_branch" ]; then
|
||||
git_text="[$git_branch]"
|
||||
else
|
||||
git_text=""
|
||||
PS1+="\[$c_branch\]/$git_branch"
|
||||
fi
|
||||
fi
|
||||
#
|
||||
@@ -164,29 +162,36 @@ if [ -n "$PS1" ]; then
|
||||
if [ -n "$prompt_check_svn" ]; then
|
||||
local svn_rev=$(svn info . 2> /dev/null | awk -F ':' '/Revision:/ { print $2 }')
|
||||
if [ -n "$svn_rev" ]; then
|
||||
svn_text="[$svn_rev]"
|
||||
else
|
||||
svn_text=""
|
||||
svn_text="@$svn_rev"
|
||||
PS1+="\[$c_branch\]\$svn_text" # svn revision
|
||||
fi
|
||||
fi
|
||||
#
|
||||
# exit code if not zero
|
||||
#
|
||||
if [ "$exit_code" -ne "0" ]; then
|
||||
exit_text="[exit=$exit_code]"
|
||||
else
|
||||
exit_text=""
|
||||
PS1+=",\[$c_exit\]rc=$exit_code"
|
||||
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=""
|
||||
if [ $jobs_bg -gt 0 ]; then
|
||||
PS1+=",\[$c_jobs\]bg=$jobs_bg"
|
||||
fi
|
||||
#
|
||||
# Info about jobs.
|
||||
#
|
||||
local jobs_stopped=$(jobs -s | wc -l | tr -d ' ')
|
||||
if [ $jobs_stopped -gt 0 ]; then
|
||||
PS1+=",\[$c_jobs\]stp=$jobs_stopped"
|
||||
fi
|
||||
|
||||
|
||||
#
|
||||
# Colors should be set here and surrounded with \[\]otherwise bash fails to
|
||||
# calculate prompt length. The text is set through PROMPT_COMMAND
|
||||
PS1+="\[$c_reset\]\$ " # reset colors and print $
|
||||
}
|
||||
# Turn on checkwinsize
|
||||
shopt -s checkwinsize
|
||||
|
||||
Reference in New Issue
Block a user