Noice!

I use a slightly different coding style -- here's mine, but I don't make anyone drink my kool aid... I prefer $() to back-ticks -- they're easier to distinguish from other quotes and far easier to nest.

I *think* that you could replace

for i in $(echo $BUGS); do
...

with 

for i in $BUGS; do
...

Haven't tested my version. Cavat Emptor.

Cheers,

--Barton
 

#!/bin/bash

if [[ ! -d ~/bugs2check ]]; then
   echo "Creating report directory..."
   mkdir ~/bugs2check
fi

git checkout master
BRANCH=$(git status | grep "On branch" | cut -f3- -d' ')
if [[ $BRANCH != "master" ]]; then
   echo "Handle your commits first."
   exit
fi

echo > ~/bugs2check/REPORT
BUGS=$(git branch | grep "bug_[0-9][0-9]*$" | cut -f2 -d'_' | sort -u)
for i in $(echo $BUGS); do
   wget -O- http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=$i > ~/bugs2check/$i 2> /dev/null
   STATUS=`grep static_bug ~/bugs2check/$i | cut -f2 -d'>'`
   echo $i - $STATUS | tee -a ~/bugs2check/REPORT
done
for STATUS in 'Pushed to Master' 'Pushed to Stable' 'CLOSED' 'RESOLVED' 
do
    BUGS2DEL=$(grep "$STATUS" ~/bugs2check/REPORT | cut -f1 -d' ')
    for i in $(echo $BUGS2DEL); do
       BRANCHES=$(git branch | grep bug_$i)
       read -p "Delete $BRANCHES? " -n 1 -r
       echo    # (optional) move to a new line
       if [[ $REPLY =~ ^[Yy]$ ]]; then
           for j in $(echo $BRANCHES); do
               git branch -D $j
           done
       fi
    done
done


On Thu, Jun 4, 2015 at 11:45 PM, Mark Tompsett <mtompset@hotmail.com> wrote:
Greetings,

If you are like me, you get a lot of branches going, and trimming back takes too much time to check if they have been pushed, etc. etc. Here’s my attempt at a script.
Obviously, my branches have bug_#### on them, and a few that don’t and obviously are unrelated to bugzilla. :)

Enjoy,
Mark Tompsett

#!/bin/bash

if [[ ! -d ~/bugs2check ]]; then
   echo "Creating report directory..."
   mkdir ~/bugs2check
fi

git checkout master
BRANCH=`git status | grep "On branch" | cut -f3- -d' '`
if [[ $BRANCH != "master" ]]; then
   echo "Handle your commits first."
   exit
fi

echo > ~/bugs2check/REPORT
BUGS=`git branch | grep "bug_[0-9][0-9]*$" | cut -f2 -d'_' | sort -u`
for i in `echo $BUGS`; do
   wget -O- http://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=$i > ~/bugs2check/$i 2> /dev/null
   STATUS=`grep static_bug ~/bugs2check/$i | cut -f2 -d'>'`
   echo $i - $STATUS | tee -a ~/bugs2check/REPORT
done
BUGS2DEL=`grep 'Pushed to Master' ~/bugs2check/REPORT | cut -f1 -d' '`
for i in `echo $BUGS2DEL`; do
   BRANCHES=`git branch | grep bug_$i`
   read -p "Delete $BRANCHES? " -n 1 -r
   echo    # (optional) move to a new line
   if [[ $REPLY =~ ^[Yy]$ ]]; then
       for j in `echo $BRANCHES`; do
           git branch -D $j
       done
   fi
done
BUGS2DEL=`grep 'Pushed to Stable' ~/bugs2check/REPORT | cut -f1 -d' '`
for i in `echo $BUGS2DEL`; do
   BRANCHES=`git branch | grep bug_$i`
   read -p "Delete $BRANCHES? " -n 1 -r
   echo    # (optional) move to a new line
   if [[ $REPLY =~ ^[Yy]$ ]]; then
       for j in `echo $BRANCHES`; do
           git branch -D $j
       done
   fi
done
BUGS2DEL=`grep 'CLOSED' ~/bugs2check/REPORT | cut -f1 -d' '`
for i in `echo $BUGS2DEL`; do
   BRANCHES=`git branch | grep bug_$i`
   read -p "Delete $BRANCHES? " -n 1 -r
   echo    # (optional) move to a new line
   if [[ $REPLY =~ ^[Yy]$ ]]; then
       for j in `echo $BRANCHES`; do
           git branch -D $j
       done
   fi
done
BUGS2DEL=`grep 'RESOLVED' ~/bugs2check/REPORT | cut -f1 -d' '`
for i in `echo $BUGS2DEL`; do
   BRANCHES=`git branch | grep bug_$i`
   read -p "Delete $BRANCHES? " -n 1 -r
   echo    # (optional) move to a new line
   if [[ $REPLY =~ ^[Yy]$ ]]; then
       for j in `echo $BRANCHES`; do
           git branch -D $j
       done
   fi
done
_______________________________________________
Koha-devel mailing list
Koha-devel@lists.koha-community.org
http://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/