Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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.
SOFTWARE.
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,24 @@ sudo cp git-status.sh /usr/local/bin
```sh
$ cd $HOME/git
$ git-status.sh
node-scrape-html
patterns
M README.md
./proxy
script-git-status
Clean node-scrape-html
Dirty patterns 1
NO git proxy
Clean script-git-status
```
For detailed view
````sh
$ cd $HOME/git
$ git-status.sh -d
Clean node-scrape-html
Dirty patterns 1 files dirty
M README.md
NO git proxy
Clean 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

78 changes: 56 additions & 22 deletions git-status.sh
Original file line number Diff line number Diff line change
@@ -1,41 +1,75 @@
#!/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
${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
echo -e $help
exit
fi

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=$@
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}$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}$dir${textreset}"
else
echo "${red}$dir${textreset}"
for l in $lines ; do
if [ ${#l} -lt 3 ] ; then
printf %s "$l "
else
echo $l
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"

## runs if detailed level is set.
if [[ $DETAILED == "True" ]]; then
git status -s
echo
fi
done
fi

fi
cd ..
fi
done
done
done