[[ $- != *i* ]] && return
default_user=lvv
default_host="ahp"
default_domain="lvvnet"
if [ 0`tput colors` -ge 8 ]; then
dir_color='CYAN'
rc_color='red'
root_id_color='magenta'
else
dir_color='bw_bold'
rc_color='bw_bold'
fi
TOSHA_host_color=yellow
TASHA_host_color=cyan
AL_host_color=green
SH_host_color=blue
LVV_host_color=blue
AHP_host_color=white
init_vcs_color=WHITE
clean_vcs_color=blue
modified_vcs_color=red
added_vcs_color=green
mixed_vcs_color=yellow
untracked_vcs_color=BLUE
op_vcs_color=MAGENTA
detached_vcs_color=RED
max_untracked=2
max_modified=4
max_added=4
max_file_list_lengh=100
black='\['`tput sgr0; tput setaf 0`'\]'
red='\['`tput sgr0; tput setaf 1`'\]'
green='\['`tput sgr0; tput setaf 2`'\]'
yellow='\['`tput sgr0; tput setaf 3`'\]'
blue='\['`tput sgr0; tput setaf 4`'\]'
magenta='\['`tput sgr0; tput setaf 5`'\]'
cyan='\['`tput sgr0; tput setaf 6`'\]'
white='\['`tput sgr0; tput setaf 7`'\]'
BLACK='\['`tput setaf 0; tput bold`'\]'
RED='\['`tput setaf 1; tput bold`'\]'
GREEN='\['`tput setaf 2; tput bold`'\]'
YELLOW='\['`tput setaf 3; tput bold`'\]'
BLUE='\['`tput setaf 4; tput bold`'\]'
MAGENTA='\['`tput setaf 5; tput bold`'\]'
CYAN='\['`tput setaf 6; tput bold`'\]'
WHITE='\['`tput setaf 7; tput bold`'\]'
bw_bold='\['`tput bold`'\]'
bell=`tput bel`
colors_reset='\['`tput sgr0`'\]'
locale |grep -qi UTF && bell=''
init_vcs_color=${!init_vcs_color}
modified_vcs_color=${!modified_vcs_color}
untracked_vcs_color=${!untracked_vcs_color}
clean_vcs_color=${!clean_vcs_color}
added_vcs_color=${!added_vcs_color}
op_vcs_color=${!op_vcs_color}
mixed_vcs_color=${!mixed_vcs_color}
detached_vcs_color=${!detached_vcs_color}
label=${1:+$1 }
unset PROMPT_COMMAND
if [ -z "$TERM" -o "$TERM" = "dumb" -o -n "$MC_SID" ]; then
unset PROMPT_COMMAND
PS1='\w> '
return 0
fi
export who_where
set_shell_title() {
xterm_title() { echo -n "]2;${@}" ; }
screen_title() {
xterm_title "sCRn $label$plain_who_where $@"
[ "$STY" ] && screen -S $STY -X title "$@"
}
case $TERM in
screen*)
screen_title "$@"
;;
xterm* | rxvt* | gnome-terminal | konsole | eterm | wterm )
xterm_title "$label$plain_who_where $@"
;;
*)
;;
esac
}
export -f set_shell_title
id=`id -un`
id=${id#$default_user}
tty=`tty`
tty=`echo $tty | sed "s:/dev/pts/:p:; s:/dev/tty::" `
tty=`echo $tty | sed "s:/dev/vc/:vc:" `
if [[ "$TERM" = "screen" ]] ; then
tty="$WINDOW"
fi
case $TERM in
xterm* | rxvt* | gnome-terminal | konsole | eterm | wterm ) unset tty ;;
*) ;;
esac
dir_color=${!dir_color}
rc_color=${!rc_color}
root_id_color=${!root_id_color}
host=${HOSTNAME}
host=`echo ${host%$default_host} | tr a-z A-Z`
host_color=${host}_host_color
host_color=${!host_color}
host_color=${!host_color}
host=${host%.localdoman}
host=${host%.$default_domain}
color_who_where="${id:+$id@}$host_color$host${tty:+ $tty}"
plain_who_where="${id:+$id@}$host"
color_who_where="${color_who_where%@}"
plain_who_where="${plain_who_where%@}"
color_who_where="$color_who_where "
plain_who_where="$plain_who_where "
color_who_where="${color_who_where## }"
plain_who_where="${plain_who_where## }"
if [ "$id" == "root" ] ; then
color_who_where="$root_id_color$color_who_where$colors_reset"
fi
parse_svn_dir() {
if [[ ! -d .svn || $HOME == $PWD ]]; then
return 1
fi
vcs=svn
eval `
svn info |
sed -n "
s@^URL[^/]*//@repo_dir=@p
s/^Revision: /rev=/p
"
`
unset status modified added clean init added mixed untracked op detached
eval `svn -q status 2>/dev/null |
sed -n "
s/^A /modified=modified; modified_files+=\" \"/p
s/^M /modified=modified; modified_files+=\" \"/p
"
`
[[ -z $modified ]] && [[ -z $untracked ]] && clean=clean
vcs_info=svn:r$rev
}
parse_git_dir() {
git_dir=`git rev-parse --git-dir 2> /dev/null`
[[ -n ${git_dir/./} ]] || return 1
vcs=git
unset status modified added clean init added mixed untracked op detached
local untracked_cnt=0;
local modified_cnt=0;
local added_cnt=0;
eval `
git status 2>/dev/null |
sed -n '
s/^# On branch /branch=/p
s/^nothing to commit (working directory clean)/clean=clean/p
s/^# Initial commit/init=init/p
/^# Untracked files:/,/^[^#]/{
s/^# Untracked files:/untracked=untracked;/p
s/^# \([^.]*\)/untracked_files[${#untracked_files[@]}+1]=\"\1\"/p
}
/^# Changed but not updated:/,/^# [A-Z]/ {
s/^# Changed but not updated:/modified=modified;/p
s/^# modified: \([^.]*\)/modified_files[${#modified_files[@]}+1]=\"\1\"/p
s/^# unmerged: \([^.]*\)/modified_files[${#modified_files[@]}+1]=\"\1\"/p
}
/^# Changes to be committed:/,/^# [A-Z]/ {
s/^# Changes to be committed:/added=added;/p
s/^# modified: \([^.]*\)/added_files[${#added_files[@]}+1]=\"\1\"/p
s/^# new file: \([^.]*\)/added_files[${#added_files[@]}+1]=\"\1\"/p
s/^# renamed:[^>]*> \([^.]*\)/added_files[${#added_files[@]}+1]=\"\1\"/p
s/^# copied:[^>]*> \([^.]*\)/added_files[${#added_files[@]}+1]=\"\1\"/p
}
'
`
if ! grep -q "^ref:" $git_dir/HEAD 2>/dev/null; then
detached=detached
fi
unset op
if [[ -d "$git_dir/.dotest" ]] ; then
if [[ -f "$git_dir/.dotest/rebasing" ]] ; then
op="rebase"
elif [[ -f "$git_dir/.dotest/applying" ]] ; then
op="am"
else
op="am/rebase"
fi
elif [[ -f "$git_dir/.dotest-merge/interactive" ]] ; then
op="rebase -i"
elif [[ -d "$git_dir/.dotest-merge" ]] ; then
op="rebase -m"
elif [[ -f "$git_dir/MERGE_HEAD" ]] ; then
op="merge"
else
[[ -f "$git_dir/BISECT_LOG" ]] && op="bisect"
fi
rawhex=`git rev-parse HEAD 2>/dev/null`
rawhex=${rawhex/HEAD/}
rawhex=${rawhex:0:6}
branch=${branch/master/M}
if [[ $init ]]; then
vcs_info=M$white=init
else
if [[ "$detached" ]] ; then
branch="<detached:`git name-rev --name-only HEAD 2>/dev/null`"
elif [[ "$op" ]]; then
branch="$op:$branch"
if [[ "$op" == "merge" ]] ; then
branch+="<--$(git name-rev --name-only $(<$git_dir/MERGE_HEAD))"
fi
fi
vcs_info="$branch$white=$rawhex"
fi
}
parse_vcs_dir() {
unset file_list modified_files untracked_files added_files
unset vcs vcs_info
unset status modified untracked added init detached
unset file_list modified_files untracked_files added_files
parse_git_dir || parse_svn_dir || return
unset status
status=${op:+op}
status=${status:-$detached}
status=${status:-$clean}
status=${status:-$modified}
status=${status:-$added}
status=${status:-$untracked}
status=${status:-$init}
: ${status?prompt internal error: git status}
eval vcs_color="\${${status}_vcs_color}"
unset vim_glob vim_file vim_files
old_nullglob=`shopt -p nullglob`
shopt -s nullglob
vim_glob=`echo .*.swp`
eval $old_nullglob
if [[ $vim_glob ]]; then
vim_file=${vim_glob#.}
vim_file=${vim_file%.swp}
[[ .${vim_file}.swp -nt $vim_file ]] && vim_files=$vim_file
fi
unset file_list
[[ ${added_files[1]} ]] && file_list+=" "$added_vcs_color${added_files[@]}
[[ ${modified_files[1]} ]] && file_list+=" "$modified_vcs_color${modified_files[@]}
[[ ${untracked_files[1]} ]] && file_list+=" "$untracked_vcs_color${untracked_files[@]}
[[ ${vim_files} ]] && file_list+=" "${RED}VIM:${vim_files}
file_list=${file_list:+:$file_list}
if [[ ${#file_list} -gt $max_file_list_lengh ]] ; then
file_list=${file_list:0:100}
file_list="${file_list% *} ..."
fi
tail_local="($vcs_info$vcs_color${file_list}$vcs_color)"
head_local="${head_local+$vcs_color $head_local\n}"
tail_local="${tail_local+$vcs_color $tail_local}${dir_color}"
}
prompt_command_function() {
rc="$?"
if [[ "$rc" == "0" ]]; then
rc=""
else
rc="$rc_color$rc$colors_reset "
fi
set_shell_title "$PWD/"
max=35
front=7
head=${PWD:0:$front}"..."
parse_vcs_dir
PS1="$head_local$colors_reset$label$rc$color_who_where$dir_color\w$tail_local$dir_color> $colors_reset"
unset head_local tail_local
}
PROMPT_COMMAND=prompt_command_function
unset rc id tty bell