sh git-multi-status.sh

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sh git-multi-status.sh相关的知识,希望对你有一定的参考价值。

#!/bin/bash

# usage: $0 source_dir [source_dir] ...
# where source_dir args are directories containing git repositories

red="\033[00;31m"
green="\033[00;32m"
yellow="\033[00;33m"
blue="\033[00;34m"
purple="\033[00;35m"
cyan="\033[00;36m"

reset="\033[00m"


if [ $# -eq 0 ] ; then
  ARGS=( "/Users/ryan/Repos/personal/QuickQuestion" "/Users/ryan/Repos/personal/sublist" )
else
  ARGS=$@
fi

for i in ${ARGS[@]} ; do
  for gitdir in `find $i -name .git` ; do
    ( working=$(dirname $gitdir)
      cd $working
      RES=$(git status | grep -E '^# (Changes|Untracked|Your branch)')
      STAT=""
      grep -e 'Untracked' <<<${RES} >/dev/null 2>&1
      if [ $? -eq 0 ] ; then
        STAT=" $red[Untracked]$reset"
      fi
      grep -e 'Changes not staged for commit' <<<${RES} >/dev/null 2>&1
      if [ $? -eq 0 ] ; then
        STAT="$STAT $red[Modified]$reset"
      fi
      grep -e 'Changes to be committed' <<<${RES} >/dev/null 2>&1
      if [ $? -eq 0 ] ; then
        STAT="$STAT $green[Staged]$reset"
      fi
      grep -e 'Your branch is ahead' <<<${RES} >/dev/null 2>&1
      if [ $? -eq 0 ] ; then
        STAT="$STAT $yellow[Unpushed]$reset"
      fi
      grep -e 'Your branch is behind' <<<${RES} >/dev/null 2>&1
      if [ $? -eq 0 ] ; then
        STAT="$STAT $cyan[Unmerged]$reset"
      fi

      if [ -n "$STAT" ] ; then
        echo -e "$working :$STAT"
      fi
    )
  done
done

以上是关于sh git-multi-status.sh的主要内容,如果未能解决你的问题,请参考以下文章

如何使我的命令行在具有扩展名(.sh)和名称如“weird.sh.sh.sh”的文件上工作

sh sh_template.sh

sh sh.sh

Linux下面如何运行 SH文件

配置告警系统主脚本main.sh mon.sh load.sh 502.sh disk.sh

shell 脚本各种执行方式(source ./*.sh, . ./*.sh, ./*.sh)的区别