Anton Shestakov <av6@dwimlabs.net>, Sun, 17 Mar 2019 13:27:28 +0800
keyboard: this one too
.bash_prompt
Permissions: -rw-r--r--
function prompt_command
{ local Kd='\[\e[0;30m\]'; local K='\[\e[0;90m\]'; local Kb='\[\e[1;30m\]' local Rd='\[\e[0;31m\]'; local R='\[\e[0;91m\]'; local Rb='\[\e[1;31m\]' local Gd='\[\e[0;32m\]'; local G='\[\e[0;92m\]'; local Gb='\[\e[1;32m\]' local Yd='\[\e[0;33m\]'; local Y='\[\e[0;93m\]'; local Yb='\[\e[1;33m\]' local Bd='\[\e[0;34m\]'; local B='\[\e[0;94m\]'; local Bb='\[\e[1;34m\]' local Pd='\[\e[0;35m\]'; local P='\[\e[0;95m\]'; local Pb='\[\e[1;35m\]' local Cd='\[\e[0;36m\]'; local C='\[\e[0;96m\]'; local Cb='\[\e[1;36m\]' if [[ $TERM == 'linux' ]] ; then local TIME="${G}\t${RESET}" if [[ $RETURN_CODE !
= 0 ]] ; then local RETCODE="${R}${RETURN_CODE}${RESET} " if [[ $EUID == 0 ]] ; then # getting hg and git info is disabled for root local HG_INFO=" ${P}-${RESET}" local GIT_INFO=" ${G}-${RESET}" if [[ $VIRTUAL_ENV ]] ; then local VENV="${G}+"$(basename
"$VIRTUAL_ENV")"${RESET}" ${K}[${RESET}${TIME} \\u@\\h \ ${RETCODE}\\W${VENV}${HG_INFO}${GIT_INFO}${K}]${RESET}\ ${PROMPT_COLOR}\\\$${RESET} " test "$PWD" == '/' && return || test -e
'.hg' && echo 'hg' && return || test -e
'.git' && echo 'git' && return || cd ..
&& _upsearch
if [[ $USE_HG_PROMPT ]] ; then local PROMPT_TEMPLATE="${P}{branch|quiet}{${Rd}{closed}}${P}☿{rev}{${B}+{tags|quiet|+}}{${Gd}*{bookmark}}{${R}{update}}{${G}+{rev|merge}}${R}{status|modified}${RESET}" HG_INFO=" $(HGPLAIN=1 hg prompt
$PROMPT_TEMPLATE)" local SUM=$(HGPLAIN=1 hg sum
2>/dev/null
) local PARENTS=($(grep -Po
'(?<=parent: ).*(?=:)' <<< "$SUM")) local BRANCH=$(grep -Po
'(?<=branch: ).*$' <<< "$SUM") local COMMIT=$(grep -Po
'(?<=commit: ).*$' <<< "$SUM") local UPDATE=$(grep -Po
'(?<=update: ).*$' <<< "$SUM") local MERGEREV=${PARENTS[1]} if [[ $REV = '-1' ]] ; then REV='' ; fi if [[ $BRANCH = 'default' ]] ; then BRANCH='' ; fi if [[ $MERGEREV ]] ; then MERGEREV="+$MERGEREV" ; fi *added*
|*modified*
|*deleted*
) HG_INFO=" ${P}${BRANCH}☿${REV}${R}${UPDATE}${G}${MERGEREV}${R}${COMMIT}${RESET}" local STATUS=$(LC_ALL=C git status
2>/dev/null
) local BRANCH=$(grep -Po
'(?<=On branch ).*$' <<< "$STATUS") local REV=$(LC_ALL=C git rev-parse --short HEAD
2>/dev/null
) local MERGEREV=$(LC_ALL=C git rev-parse --short MERGE_HEAD
2>/dev/null
) local STASH=$(LC_ALL=C git stash list
2>/dev/null
) if [[ $STATUS == *
'Your branch is behind'*
]] ; then [[ $STATUS =~
'behind '[^
$'\n']+
' '([0-9
]+
)' commit' ]] && BEHIND+=${BASH_REMATCH[1]} if [[ $STATUS == *
'Your branch is ahead'*
]] ; then [[ $STATUS =~
'ahead '[^
$'\n']+
' '([0-9
]+
)' commit' ]] && AHEAD+=${BASH_REMATCH[1]} if [[ $STATUS == *detached*
]] ; then if [[ $STATUS == *
'Changes to be committed'*
]] ; then if [[ $STATUS == *
'Changes not staged'*
]] ; then if [[ $STATUS == *
'You have unmerged paths.'*
]] ; then local MERGE="$R+$MERGEREV" if [[ $STATUS == *
'All conflicts fixed but you are still merging.'*
]] ; then local MERGE="$B+$MERGEREV" if [[ ! -z
$STASH ]] ; then GIT_INFO=" ${G}${BRANCH}±${REV}${MERGE}${BEHIND}${AHEAD}${STAGED}${UNSTAGED}${C}${STASH}${RESET}" # first find prompt in hgrc, then check it's actually enabled if grep -w
'^prompt' ~/.hgrc
&>/dev/null
&& hg
help prompt
&>/dev/null
; then export VIRTUAL_ENV_DISABLE_PROMPT=1 export PROMPT_COMMAND=prompt_command