blog_20140424_1_3578033 50行 Text
Raw
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
#!/bin/bash
function count() {
local insert=0
local delete=0
while read line ;do
current=`echo $line| awk -F',' '{printf $2}' | awk '{printf $1}'`
if [[ -n $current ]]; then
insert=`expr $insert + $current`
fi
current=`echo $line | sed -n 's/.*, //p' | awk '{printf $1}'`
if [[ -n $current ]]; then
delete=`expr $delete + $current`
fi
done < .tmp.count
echo "$insert insertions, $delete deletions"
}

function countAll() {
git log --author=msdx --shortstat --pretty=format:"" | sed /^$/d >.tmp.count
count;
rm .tmp.count
}

function countToday() {
local current=`date +%s`;
local begin=`date +%Y-%m-%d |xargs date +%s -d`;
local minutes=$(($current - $begin));

git log --author=msdx --since="$minutes seconds ago" --shortstat --pretty=format:"" | sed /^$/d >.tmp.count
count;
rm .tmp.count

}

function countOneDay() {
git log --author=msdx --since="1 days ago" --shortstat --pretty=format:"" | sed /^$/d >.tmp.count
count;
rm .tmp.count

}

if [[ ! -n $1 ]] || [[ $1 = "all" ]] ; then
countAll;
elif [[ $1 = "oneday" ]]; then
countOneDay;
elif [[ $1 = "today" ]]; then
countToday;
else
echo "args: all | oneday | today";
fi