summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugues Hiegel <hugues.hiegel@qosmos.com>2013-08-06 10:30:34 +0200
committerHugues Hiegel <hugues.hiegel@qosmos.com>2013-08-06 16:15:00 +0200
commit5cef725a76808a81e58248f79e1404ca8a7e008a (patch)
tree306b33eee5e3139016639d78535b80755ac1d1be
parent3d6a612651035f831ea3049747e4a1dcd6d879ed (diff)
[Git] submodules statuses shown in taskbar
-rw-r--r--01_Internal.zsh56
-rw-r--r--12_Prompts.zsh95
2 files changed, 68 insertions, 83 deletions
diff --git a/01_Internal.zsh b/01_Internal.zsh
index 6a04817..4f02855 100644
--- a/01_Internal.zsh
+++ b/01_Internal.zsh
@@ -112,7 +112,7 @@ __get_gcl_branch ()
case $1 in
git)
__debug -n " GIT status..."
- __get_git_branch
+ __get_git_infos
__debug
;;
hg)
@@ -136,6 +136,22 @@ __get_hg_branch ()
__cleanup_git_branch_name() { sed 's,^tags/,,;s,^remotes/,,;s,\^0$,,' }
+__get_git_fullstatus ()
+{
+ [ -n "$1" ] && pushd $1 >/dev/null
+
+ local _branch _status
+
+ _branch=$(__get_git_branch)
+ _status=$(__get_git_branch_status)
+
+ [ -n "$_branch" ] && _branch=$C_$_prompt_colors[soft_generic]$_C${${_branch/→/$C_$_status$_C}/←/$C_$_prompt_colors[soft_generic]$_C}$C_$color[none]$_C
+
+ [ -n "$1" ] && popd >/dev/null
+
+ echo "$_branch"
+}
+
__get_git_branch ()
{
local my_git_branch checkouted_branch="yes"
@@ -154,14 +170,16 @@ __get_git_branch ()
__debug
__debug -n " branch..."
+ GIT_DIR=$(git rev-parse --git-dir 2>&-)
# Get git branch only from git managed folders (not ignored subfolders..)
- [ "$( ( git ls-files ; git ls-tree HEAD . ) 2>&- | head -n1)" = "" -a \( ! -d .git -o "$(git rev-parse --git-dir 2>&-)" != ".git" \) -a "$(git rev-parse --is-inside-git-dir 2>&-)" != "true" ] && return
-
- GIT_DIR=$(git rev-parse --git-dir)
+ [ "$( ( git ls-files ; git ls-tree HEAD . ) 2>&- | head -n1)" = "" -a \
+ \( ! -d .git -o -z "$GIT_DIR" \) -a \
+ "$(git rev-parse --is-inside-git-dir 2>&-)" != "true" ] && return
# Get current working GIT branch
my_git_branch="$(git branch 2>&- | grep -E '^\* ' | cut -c3-)"
+
if [ "$my_git_branch" != "" ]
then
# If not on a working GIT branch, get the named current commit-ish inside parenthesis
@@ -324,26 +342,29 @@ __get_guilt_series ()
# We *must* have previously checked that
# we obtained a correct GIT branch with
# a call to `__get_git_branch`
-__get_git_status ()
+__get_git_branch_status ()
{
- local my_git_status cached changed managment_folder
+ local my_git_branch_status cached changed managment_folder
+
+ GIT_DIR=$(git rev-parse --git-dir 2>/dev/null)
+ [ -z "$GIT_DIR" ] && return
if [ "$(git config --get zsh.check-status)" = "false" ]
then
return
fi
- my_git_status=$_gcl_colors[uptodate];
+ my_git_branch_status=$_gcl_colors[uptodate];
__debug -n " where to..."
if [ -f ".repo/manifests.git/config" ]
then
- echo $my_git_status
+ echo $my_git_branch_status
return
fi
- if [ "$(git rev-parse --is-inside-git-dir)" = "true" -o "$(git config --get core.bare)" = "true" ] ; then
+ if [ "$(git rev-parse --is-inside-git-dir 2>/dev/null)" = "true" -o "$(git config --get core.bare)" = "true" ] ; then
echo "$_gcl_colors[gitdir]"
return
fi
@@ -360,23 +381,22 @@ __get_git_status ()
__debug
__debug -n " cached/changed..."
- GIT_DIR=$(git rev-parse --git-dir 2>/dev/null)
if [ "$cached" != "" -a "$changed" != "" ]
then
- my_git_status="$_gcl_colors[mixed]"
+ my_git_branch_status="$_gcl_colors[mixed]"
elif [ "$cached" != "" ]
then
- my_git_status="$_gcl_colors[cached]"
+ my_git_branch_status="$_gcl_colors[cached]"
elif [ "$changed" != "" ]
then
- my_git_status="$_gcl_colors[changed]"
+ my_git_branch_status="$_gcl_colors[changed]"
elif [ "$(git cat-file -t HEAD 2>/dev/null)" != "commit" ]
then
if [ ! -z "$(git ls-files)" ] ; then
- my_git_status="$_gcl_colors[cached]"
+ my_git_branch_status="$_gcl_colors[cached]"
else
- my_git_status="$_gcl_colors[init]"
+ my_git_branch_status="$_gcl_colors[init]"
fi
fi
@@ -385,17 +405,17 @@ __get_git_status ()
__debug -n " diverged..."
if [ $(git status . | sed -n '2{/have diverged/p;q}' | wc -l) -gt 0 ]
then
- my_git_status+=";$color[standout]"
+ my_git_branch_status+=";$color[standout]"
fi
__debug
__debug -n " merges..."
if [ $(git ls-files --unmerged | wc -l) -gt 0 ]
then
- my_git_status="${_gcl_colors[merging]:+$_gcl_colors[merging];}$my_git_status"
+ my_git_branch_status="${_gcl_colors[merging]:+$_gcl_colors[merging];}$my_git_branch_status"
fi
- echo $my_git_status
+ echo $my_git_branch_status
__debug
}
diff --git a/12_Prompts.zsh b/12_Prompts.zsh
index 6afbc09..dc6ffdc 100644
--- a/12_Prompts.zsh
+++ b/12_Prompts.zsh
@@ -157,6 +157,13 @@ __ssh_gpg_agents ()
}
PS1_TASKBAR+=(__ssh_gpg_agents)
+__display ()
+{
+ __debug -n " Display..."
+ echo ${DISPLAY:+$C_$_prompt_colors[display]$_C"("$DISPLAY")"}
+ __debug
+}
+PS1_TASKBAR+=(__display)
__vcsbranch ()
{
@@ -204,69 +211,35 @@ __vcsbranch ()
# get git status
#
- GITBRANCH=$(__get_gcl_branch git)
- GITBRANCHSIZE=${#GITBRANCH}
- [ $GITBRANCHSIZE -gt 0 ] && GITBRANCHSIZE=$(($GITBRANCHSIZE))
-
- #
- #__debug -n " Path..."
- #PATHSIZE=$(print -Pn $CURDIR)
- #PATHSIZE=${#PATHSIZE}
- #__debug
- #__debug -n " Resize path / gitbranch..."
- #spaceleft=`__expand_text "%n@%m${DISPLAY:+($DISPLAY)} $ ls -laCdtrux $DATE"`
- #spaceleft=$(($COLUMNS - ${#spaceleft}))
- ##minimalpathsize=`print -Pn "../%1~"`
- ##minimalpathsize=${#minimalpathsize}
- #minimalpathsize=10
- #minimalgitsize=10 # git-abbrev-commit-ish...
- #if [ $GITBRANCHSIZE -gt 0 ]
- #then
- # if [ $spaceleft -lt $(( $PATHSIZE + $GITBRANCHSIZE )) ]
- # then
- # CHUNKABLE=${${GITBRANCH/*→/}/←*/}
- #
- # # reduce the git-branch until it is shrinked to $minimalgitsize characters max.
- # if [ $GITBRANCHSIZE -gt $minimalgitsize ]
- # then
- # GITBRANCHCHUNK=$(( $GITBRANCHSIZE - ($spaceleft - $PATHSIZE) ))
- # [ $((${#CHUNKABLE} - $GITBRANCHCHUNK)) -lt $minimalgitsize ] && GITBRANCHCHUNK=$((${#CHUNKABLE} - $minimalgitsize))
- # fi
- # CHUNKABLE=`print -Pn "%"$(( ${#CHUNKABLE} - ${GITBRANCHCHUNK:-0} ))">¬>"${CHUNKABLE%\~*}`
- #
- # GITBRANCH=${GITBRANCH/→*←/→$CHUNKABLE←}
- # fi
- #fi
- # then we reduce the path until it reaches the last path element,
- #spaceleft=$(($spaceleft - $GITBRANCHSIZE))
- #[ $spaceleft -lt $minimalpathsize ] && spaceleft=$minimalpathsize
- #__debug
-
- if [ -n "$GITBRANCH" ]
- then
- GITBRANCH=$C_$_prompt_colors[soft_generic]$_C${${GITBRANCH/→/$C_"$(__get_git_status)"$_C}/←/$C_$_prompt_colors[soft_generic]$_C}"$(__get_guilt_series)$C_$color[none]$_C"
-
- # Get recursive submodules statuses
- GIT_DIR=$(git rev-parse --git-dir)
- for SUBMODULE in $(git config --get core.recursive)
- do
- pushd $(dirname $GIT_DIR)/$SUBMODULE >/dev/null
- SUBBRANCH=${$(__get_git_branch)//→master←/→…←}
- SUBSTATUS=$(__get_git_status)
- popd >/dev/null
- GITBRANCH+=$C_$color[black]$_C"₊"$C_$_prompt_colors[soft_generic]$_C
- GITBRANCH+=${${SUBBRANCH/→/$C_"$SUBSTATUS"$_C}/←/$C_$_prompt_colors[soft_generic]$_C}
- GITBRANCH+=$C_$color[none]$_C
- done
- fi
-
-
+ GITBRANCH=$(__get_git_fullstatus)
[ -n "$GITBRANCH" ] && vcsbranch+=${vcsbranch:+ }$GITBRANCH
echo $vcsbranch
}
PS1_EXTRA_INFO+=(__vcsbranch)
+__subvcsbranches () {
+ local GITBRANCH
+
+ GIT_DIR=$(git rev-parse --git-dir 2>/dev/null)
+ [ "$( ( git ls-files ; git ls-tree HEAD . ) 2>&- | head -n1)" = "" -a \
+ \( ! -d .git -o -z "$GIT_DIR" \) -a \
+ "$(git rev-parse --is-inside-git-dir 2>&-)" != "true" ] && return
+
+ # Get recursive submodules statuses
+ for SUBMODULE in $(git config --get zsh.recurse-dirs)
+ do
+ if [ -d $(dirname $GIT_DIR)/$SUBMODULE ]
+ then
+ GITBRANCH+=${GITBRANCH:+$(tput cuf1)}
+ GITBRANCH+=$(__get_git_fullstatus $(dirname $GIT_DIR)/$SUBMODULE)
+ fi
+ done
+ echo $GITBRANCH
+
+}
+PS1_TASKBAR+=(__subvcsbranches)
+
__redefine_prompt ()
{
case "$_yeahconsole" in
@@ -291,14 +264,6 @@ __show_date()
echo $(tput cub $COLUMNS ; tput cuf $(($COLUMNS - $DATESIZE)))$DATE
}
-__display ()
-{
- __debug -n " Display..."
- echo ${DISPLAY:+$C_$_prompt_colors[display]$_C"("$DISPLAY")"}
- __debug
-}
-PS1_TASKBAR+=(__display)
-
__display_vi_mode()
{
__debug -n " vimode..."