Commits

raichoo  committed 08026a0

tags.cache fix and code cleanup

  • Participants
  • Parent commits ba47ea1

Comments (0)

Files changed (1)

 fi
 
 function _checkrevision {
-	if [[ $SHELLMODE == "hg" ]]
-	then
-		set -A HGOUTPUT -- $(hg id -n -b 2> /dev/null) 
-		if [[ "${HGOUTPUT[0]%%*+}" == "" ]]
-		then
-			print "${RED}${HGOUTPUT[0]}${NORM}@${CYAN}${HGOUTPUT[1]}" && return
-		else
-			if [[ "${HGOUTPUT[0]}" == "$(head -n 1 ${VCSROOT}/.hg/tags.cache | awk '{ print $1 }')" ]]
+	case $SHELLMODE in
+		hg)
+			set -A HGOUTPUT -- $(hg id -n -b 2> /dev/null) 
+			if [[ "${HGOUTPUT[0]%%*+}" == "" ]]
 			then
-				print "${GREEN}${HGOUTPUT[0]}${NORM}@${CYAN}${HGOUTPUT[1]}" && return
+				print "${RED}${HGOUTPUT[0]}${NORM}@${CYAN}${HGOUTPUT[1]}" && return
 			else
-				print "${YELLOW}${HGOUTPUT[0]}${NORM}@${CYAN}${HGOUTPUT[1]}" && return
+				if (( ${HGOUTPUT[0]} >= $(head -n 1 ${VCSROOT}/.hg/tags.cache | awk '{ print $1 }') ))
+				then
+					print "${GREEN}${HGOUTPUT[0]}${NORM}@${CYAN}${HGOUTPUT[1]}" && return
+				else
+					print "${YELLOW}${HGOUTPUT[0]}${NORM}@${CYAN}${HGOUTPUT[1]}" && return
+				fi
 			fi
-		fi
-	elif [[ $SHELLMODE == "git" ]]
-	then
-		GITSTATUS=$(git status -s)
-		GITBRANCH=$(git branch --no-color 2> /dev/null | egrep --color=never '^\*')
-		GITREV=$(git show-ref -h HEAD 2> /dev/null) 
-		if [[ ${GITBRANCH:2} == "(no branch)" ]]
-		then
-			GITBRANCH=${RED}${GITBRANCH:2}
-		else
-			GITBRANCH=${CYAN}${GITBRANCH:2}
-		fi
-		if [[ $(echo $GITSTATUS | egrep '^ ?[M|A|R]') != "" ]]
-		then
-			print "${RED}${GITREV:0:7}${NORM}@${GITBRANCH}" && return
-		else
-			if [[ ${GITREV:0:40} == $(git log --no-color --pretty=oneline --all -n 1 | cut -d ' ' -f1) ]]
+			;;
+		git)
+			GITSTATUS=$(git status -s)
+			GITBRANCH=$(git branch --no-color 2> /dev/null | egrep --color=never '^\*')
+			GITREV=$(git show-ref -h HEAD 2> /dev/null) 
+			if [[ ${GITBRANCH:2} == "(no branch)" ]]
 			then
-				print "${GREEN}${GITREV:0:7}${NORM}@${GITBRANCH}" && return
+				GITBRANCH=${RED}${GITBRANCH:2}
 			else
-				print "${YELLOW}${GITREV:0:7}${NORM}@${GITBRANCH}" && return
+				GITBRANCH=${CYAN}${GITBRANCH:2}
 			fi
-		fi
-	fi
+			if [[ $(echo $GITSTATUS | egrep '^ ?[M|A|R]') != "" ]]
+			then
+				print "${RED}${GITREV:0:7}${NORM}@${GITBRANCH}" && return
+			else
+				if [[ ${GITREV:0:40} == $(git log --no-color --pretty=oneline --all -n 1 | cut -d ' ' -f1) ]]
+				then
+					print "${GREEN}${GITREV:0:7}${NORM}@${GITBRANCH}" && return
+				else
+					print "${YELLOW}${GITREV:0:7}${NORM}@${GITBRANCH}" && return
+				fi
+			fi
+			;;
+		esac
 }
 
 function _cd {
 			export PS1=$MAINPROMPT && return
 			;;
 		hg)
-			alias cd='_cd'
-			alias rm='_rm'
-			alias mv='_mv'
 			export SHELLMODE="hg"
 			export VCSROOT="$(hg root 2> /dev/null)"
 			if [[ $VCSROOT == "" ]]
 			then
 				mode ksh && return
 			fi
+			alias cd='_cd'
+			alias rm='_rm'
+			alias mv='_mv'
 			export PS1='${PURPLE}☿${NORM}:${BOLD}$(_checkrevision)${NORM}:${BLUE}$(_checkdir)${NORM}> '
 			;;
 		git)
 			export SHELLMODE="git"
 			TMPROOT="./$(git rev-parse --show-cdup 2> /dev/null)"
-			if [[ $TMPROOT == "./" ]]
+			if [[ $TMPROOT == "./" ]] && [ ! -d .git ]
 			then
-				if [ ! -d .git ]
-				then
-					mode ksh && return
-				fi
+				mode ksh && return
 			fi
 			TMPBUFFER=$PWD
 			cd $TMPROOT