From 68ecfe42dc1a5442bed10e551cf6ab519a3b29a2 Mon Sep 17 00:00:00 2001 From: Eideen Date: Thu, 18 Jul 2019 00:16:01 +0200 Subject: [PATCH 1/4] Updated license made the display of dirty files option. Add text to display Clean/drit/NO git Add -h/--help --- LICENSE | 3 ++- README.md | 12 ++++++++++-- git-status.sh | 42 +++++++++++++++++++++++++++++++++--------- 3 files changed, 45 insertions(+), 12 deletions(-) diff --git a/LICENSE b/LICENSE index a682c19..493d227 100644 --- a/LICENSE +++ b/LICENSE @@ -1,5 +1,6 @@ The MIT License (MIT) +Copyright (c) 2019 Eideen Copyright (c) 2014 markmontymark Permission is hereby granted, free of charge, to any person obtaining a copy @@ -18,4 +19,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. \ No newline at end of file +SOFTWARE. diff --git a/README.md b/README.md index ee1114b..bc8de73 100644 --- a/README.md +++ b/README.md @@ -21,14 +21,22 @@ $ cd $HOME/git $ git-status.sh node-scrape-html patterns -M README.md ./proxy script-git-status ``` +For detailed view +````sh +$ cd $HOME/git +$ git-status.sh -d +node-scrape-html +patterns +M README.md +./proxy +script-git-status +```` ## color meanings - green - clean status, no changes to stage, commit or push - red - dirty status, you have changes to stage, commit or push - blue - no .git/ directory found, so not a git repo - diff --git a/git-status.sh b/git-status.sh index c10c7e1..3cf41de 100755 --- a/git-status.sh +++ b/git-status.sh @@ -1,17 +1,38 @@ #!/bin/bash -## green means no uncommited changes -- you're good -## yellow means staged but not committed changes -## red means changes exist, nut no staged changes yet -## blue means not a git repo - textreset=$(tput sgr0) # reset the foreground colour red=$(tput setaf 1) green=$(tput setaf 2) yellow=$(tput setaf 3) blue=$(tput setaf 4) -checkdirs=$@ +help="Usage: git-status.sh [-d/-h/--help] [DIR]\n +Example: 'git-status.sh -d'\n +\n +Options:\n + -d Gived detailed listing of files that are not committed. \n + -h show this help info (for MOTD)\n +\n +- ${green}Green${textreset} means no uncommited changes -- you're good. \n +- ${yellow}Yellow${textreset} means staged but not committed changes.\n +- ${red}Red${textreset} means changes exist, nut no staged changes yet.\n +- ${blue}Blue${textreset} means not a git repo.\n +" +# Check if shell is launched with parameter "-c" +if [[ "$@" == *'-h'* ]] || [[ "$@" == *'--help'* ]]; then + echo -e $help + exit +fi + +if [[ "$@" == *'-d'* ]]; then + DETAILED=True + # Removes the "-d", and sends the + checkdirs=${@/-d/} +else + DETAILED=False + checkdirs=$@ +fi + if [ "$checkdirs" == "" ]; then checkdirs=(.) fi @@ -19,14 +40,16 @@ fi for checkdir in $checkdirs ; do for dir in `ls $checkdir` ; do if [ ! -d "$checkdir/$dir/.git" ] ; then - echo "${blue}$checkdir/$dir${textreset}" + echo "${blue}NO git $checkdir/$dir${textreset}" else cd "$checkdir/$dir" lines=`git status --porcelain` if [ ${#lines[@]} -lt 2 -a "$lines" == "" ] ; then - echo "${green}$dir${textreset}" + echo "${green}Clean $dir${textreset}" else - echo "${red}$dir${textreset}" + echo "${red}Dirty $dir${textreset}" + + if [[ $DETAILED == "True" ]]; then for l in $lines ; do if [ ${#l} -lt 3 ] ; then printf %s "$l " @@ -34,6 +57,7 @@ for checkdir in $checkdirs ; do echo $l fi done + fi fi cd .. fi From 321d020943adeb72dd574e77878c1d356a174aa2 Mon Sep 17 00:00:00 2001 From: Eideen Date: Thu, 18 Jul 2019 00:20:21 +0200 Subject: [PATCH 2/4] Add display of number of dirty files. --- git-status.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-status.sh b/git-status.sh index 3cf41de..7c5c33d 100755 --- a/git-status.sh +++ b/git-status.sh @@ -47,7 +47,7 @@ for checkdir in $checkdirs ; do if [ ${#lines[@]} -lt 2 -a "$lines" == "" ] ; then echo "${green}Clean $dir${textreset}" else - echo "${red}Dirty $dir${textreset}" + echo "${red}Dirty $dir${textreset} $(git status --porcelain | wc -l) files dirty" if [[ $DETAILED == "True" ]]; then for l in $lines ; do From 3b70e92ff492bfce30112f274f752d80d4109e8a Mon Sep 17 00:00:00 2001 From: Eideen Date: Thu, 18 Jul 2019 00:23:05 +0200 Subject: [PATCH 3/4] Updated README to reflect changes. --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index bc8de73..bd693c1 100644 --- a/README.md +++ b/README.md @@ -19,20 +19,20 @@ sudo cp git-status.sh /usr/local/bin ```sh $ cd $HOME/git $ git-status.sh -node-scrape-html -patterns -./proxy -script-git-status +Clean node-scrape-html +patterns 1 +NO git ./proxy +Clean script-git-status ``` For detailed view ````sh $ cd $HOME/git $ git-status.sh -d -node-scrape-html -patterns +Clean node-scrape-html +Dirty patterns 1 files dirty M README.md -./proxy -script-git-status +NO git ./proxy +Clean script-git-status ```` ## color meanings From b7c58171c6e0472fddf1d07d88a05b6e9fd6f4b8 Mon Sep 17 00:00:00 2001 From: Eideen Date: Thu, 18 Jul 2019 02:00:53 +0200 Subject: [PATCH 4/4] fix to help, and parametere "if". Made the path more consistent. made the detailed logic easyer. --- README.md | 6 +++--- git-status.sh | 50 ++++++++++++++++++++++++++++++-------------------- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index bd693c1..32e95d5 100644 --- a/README.md +++ b/README.md @@ -20,8 +20,8 @@ sudo cp git-status.sh /usr/local/bin $ cd $HOME/git $ git-status.sh Clean node-scrape-html -patterns 1 -NO git ./proxy +Dirty patterns 1 +NO git proxy Clean script-git-status ``` For detailed view @@ -31,7 +31,7 @@ $ git-status.sh -d Clean node-scrape-html Dirty patterns 1 files dirty M README.md -NO git ./proxy +NO git proxy Clean script-git-status ```` diff --git a/git-status.sh b/git-status.sh index 7c5c33d..f4f2ab9 100755 --- a/git-status.sh +++ b/git-status.sh @@ -10,13 +10,15 @@ help="Usage: git-status.sh [-d/-h/--help] [DIR]\n Example: 'git-status.sh -d'\n \n Options:\n - -d Gived detailed listing of files that are not committed. \n - -h show this help info (for MOTD)\n +${red} -d, --detailed${textreset} Gived detailed listing of files that are not committed. \n +${red} -h, --help${textreset} show this help info (for MOTD)\n \n - ${green}Green${textreset} means no uncommited changes -- you're good. \n - ${yellow}Yellow${textreset} means staged but not committed changes.\n - ${red}Red${textreset} means changes exist, nut no staged changes yet.\n - ${blue}Blue${textreset} means not a git repo.\n + +Only folder are analysed, files are skipped. " # Check if shell is launched with parameter "-c" if [[ "$@" == *'-h'* ]] || [[ "$@" == *'--help'* ]]; then @@ -24,10 +26,14 @@ if [[ "$@" == *'-h'* ]] || [[ "$@" == *'--help'* ]]; then exit fi -if [[ "$@" == *'-d'* ]]; then +if [[ "$@" == *'-d'* ]] ; then DETAILED=True # Removes the "-d", and sends the checkdirs=${@/-d/} +elif [[ "$@" == *'--detailed'* ]]; then + DETAILED=True + # Removes the "-d", and sends the + checkdirs=${@/--detailed/} else DETAILED=False checkdirs=$@ @@ -35,31 +41,35 @@ fi if [ "$checkdirs" == "" ]; then checkdirs=(.) + PWD1="" + fi for checkdir in $checkdirs ; do - for dir in `ls $checkdir` ; do - if [ ! -d "$checkdir/$dir/.git" ] ; then - echo "${blue}NO git $checkdir/$dir${textreset}" + cd $checkdir + if [[ ! $PWD1 == "" ]]; then + PWD1=$(pwd)/ + fi + + for dir in `find * -maxdepth 0 -type d` ; do + if [[ ! -d "$dir/.git" ]] ; then + echo "${blue}NO git $PWD1$dir${textreset}" else cd "$checkdir/$dir" - lines=`git status --porcelain` - if [ ${#lines[@]} -lt 2 -a "$lines" == "" ] ; then - echo "${green}Clean $dir${textreset}" - else - echo "${red}Dirty $dir${textreset} $(git status --porcelain | wc -l) files dirty" + dirtyC=$(git status --porcelain | wc -l) + if [ $dirtyC == 0 ] ; then + echo "${green}Clean $PWD1$dir${textreset}" + else + echo "${red}Dirty $PWD1$dir${textreset} $dirtyC files dirty" - if [[ $DETAILED == "True" ]]; then - for l in $lines ; do - if [ ${#l} -lt 3 ] ; then - printf %s "$l " - else - echo $l + ## runs if detailed level is set. + if [[ $DETAILED == "True" ]]; then + git status -s + echo fi - done + fi - fi cd .. fi - done + done done