0

我想通过散布的评论使每个操作都保持在自己的位置上

如果没有 kludgy 临时文件,是否有办法做到这一点

    #!/bin/sh

    git diff --stat `git hash-object -t tree /dev/null` > tmp.txt

    # not my code
    grep -v "^ kazmath" tmp.txt > tmp2.txt

    grep -v "\.obj " tmp2.txt > tmp.txt
    grep -v "\.png " tmp.txt > tmp2.txt
    grep -v "\.gbo " tmp2.txt > tmp.txt

    # not my code
    grep -v "obj2opengl\.pl " tmp.txt > tmp2.txt

    grep -v "\.txt " tmp2.txt > tmp.txt
    grep -v "\.md " tmp.txt > tmp2.txt
    grep -v "\.blend " tmp2.txt > tmp.txt

    # +'s at end of line
    sed 's/+*$//' tmp.txt > tmp2.txt

    # ditch last line
    sed '$d' < tmp2.txt > tmp.txt

    echo -n "lines of code "
    cut -d '|' -f 2 tmp.txt | awk '{ sum+=$1} END {print sum}'

    rm tmp.txt
    rm tmp2.txt
4

1 回答 1

1

将管道和更强大的正则表达式与grep -E(aka egrep) 一起使用:

git diff --stat `git hash-object -t tree /dev/null` |
grep -v "^ kazmath" |
grep -E -v "\.(png|gbo|obj|txt|md|blend) " |
grep -v "obj2opengl\.pl " |
sed -e 's/+*$//' -e '$d' |
cut -d '|' -f 2 |
awk '{sum += $1 } END { print "lines of code " sum }'
于 2012-07-16T07:32:57.153 回答