Shell腳本實(shí)現(xiàn)的基于SVN的代碼提交量統(tǒng)計(jì)工具
最近沒(méi)啥事,就用bash寫了一個(gè)基于svn的代碼統(tǒng)計(jì)小工具。 可以指定統(tǒng)計(jì)的目錄,默認(rèn)遞歸統(tǒng)計(jì)子目錄。
目前還沒(méi)有屏蔽指定目錄的功能。哈 代碼比較粗糙。不過(guò)先曬出來(lái)。
#!/bin/bash - #"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" # FILE: lines.sh # # USAGE: ./lines.sh [dir] # AUTHOR: william # # DESCRIPTION: 基于SVN的代碼提交量統(tǒng)計(jì)工具 # OPTIONS: --- # CREATED: 06/05/2012 12:49:20 PM CST #""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" set -o nounset # Treat unset variables as an error # 關(guān)注的文件類型 后罪名 FILES_TYPE="*.cpp *.h *.lua" # 需要統(tǒng)計(jì)的人員,在這里寫入需要統(tǒng)計(jì)的人,用空格隔開(kāi)。哈還不智能 declare -r CODER_LIST="coder1 coder2" declare -i coder1 declare -i coder2 declare -r USAGE="Usage: $0 [dir]. default dir is current dir.\n" # ERROR CODES; declare -r E_BAD_PATH=1 declare -r E_INVAILED_ARGU=2 declare -r E_NOT_SVN_DIR=3 #TODO 屏蔽一些dir 還沒(méi)寫哈 # TODO other way get path not with / end getpath() { #debug #echo dir_name: ${dir_name} #echo base_name: ${base_name} if [ $dir_name == "/" ] || [ $base_name == "/" ]; then work_path="/" else work_path=${dir_name}/${base_name} fi } statistic_codelines() { if [ -z "$1" ]; then echo "ERROR statistic_codelines not argument" return fi local pwd_length=${#PWD} echo "--------------------------" echo "${PWD}" for coder in $CODER_LIST; do local num=$(echo "$1" | grep ${coder} | wc -l) (( ${coder} += num )) if [ $num -ne 0 ]; then printf "%10s | %-7d\n" ${coder} $num fi done echo "--------------------------" } # init check argument set work_path init_work_path() { if [ $# -eq 1 ]; then if [ $1 == "-h" ]; then # is help echo -e "$USAGE" elif [ -d $1 ]; then dir_name=$(dirname ${1}) base_name=$(basename ${1}) getpath; else echo -e "An invailed argument" echo -e "Use -h get help." exit $E_INVAILED_ARGU fi fi } # check work_path check_work_path() { if [ -z $work_path ] || [ ! -d $work_path ]; then exit $E_BADPATH; fi } # enter work_path enter_work_path() { cd ${work_path} if [ ! $? ]; then echo "Can not enter ${work_path} " fi } # check work_pat is a svn dir is_svn_dir() { ( # check if current dir is asvn dir svn info &> /dev/null exit $? ) return $? } action() { local dir_name=. local base_name= local work_path=$dir_name init_work_path $1 check_work_path enter_work_path #todo can't enter #echo "NOW DIR: $PWD, OLD DIR $OLDPWD" is_svn_dir #todo to next dir local ret=$? if [ $ret -ne 0 ] then echo -e "Current dir \"${work_path}\" not a svn dir." exit $E_NOT_SVN_DIR fi # get source files local files=$(ls ${FILES_TYPE} 2> /dev/null) if [ -n "$files" ]; then local namelist=$(echo -n ${files} | xargs -n 1 svn blame | awk '{print $2}') #svn blame $files #| grep $1 | wc -l statistic_codelines "$namelist" fi local sub_dirs=$(find -maxdepth 1 -type d -name "[^.]*" 2>/dev/null) if [ -n "$sub_dirs" ]; then for dir in $sub_dirs ; do action "$dir" done fi cd .. } total() { echo "-------- TOTOAL ----------" echo " NAME | lines " echo "--------------------------" for coder in $CODER_LIST; do if [ ${!coder} -ne 0 ]; then printf "%10s | %-7d\n" ${coder} ${!coder} fi done echo "--------------------------" } # main echo "-----開(kāi)始統(tǒng)計(jì),請(qǐng)耐心等待.... :) " action $1 total exit 0
- Ubuntu下定時(shí)提交代碼到SVN服務(wù)器的Shell腳本分享
- Linux svn的搭建與使用(圖文詳解)
- SVN 安裝教程之服務(wù)器和客戶端
- Eclipse 安裝 SVN 在線插件教程
- CentOS下搭建SVN服務(wù)器的步驟詳解
- svn 清理失敗 (cleanup 失敗) 的快速解決方法
- Eclipse、MyEclipse 導(dǎo)入svn項(xiàng)目具體步驟
- 使用AndroidStudio上傳忽略文件至SVN Server的解決辦法
- Android Studio與SVN版本控制程序的協(xié)作使用指南
- 圖解SVN服務(wù)器搭建和使用(一)
- windows下svn服務(wù)器快速搭建圖文教程
- Windows下SVNServer安裝與配置詳解
- SVN無(wú)法提交出現(xiàn) Can''t set file "/db/txn_current" read-write :拒絕訪問(wèn)
相關(guān)文章
Linux命令行循環(huán)執(zhí)行shell命令
這篇文章主要介紹了Linux命令行,循環(huán)執(zhí)行shell命令的相關(guān)知識(shí),主要包括死循環(huán),普通計(jì)數(shù)循環(huán),以及Linux shell循環(huán)命令 while死循環(huán)的用法,需要的朋友可以參考下2023-01-01linux BASH shell下設(shè)置字體及背景顏色
這篇文章主要介紹了linux BASH shell下設(shè)置字體及背景顏色的方法,需要的朋友可以參考下2014-04-04給定鏈表中間節(jié)點(diǎn)指針,刪除中間節(jié)點(diǎn)的方法
本文實(shí)現(xiàn)算法來(lái)刪除單鏈表中的中間節(jié)點(diǎn),只知道指向該節(jié)點(diǎn)中間節(jié)點(diǎn)的指針,大家可以參考使用2013-11-11Linux監(jiān)控cpu以及內(nèi)存使用情況之top命令(詳解)
下面小編就為大家?guī)?lái)一篇Linux監(jiān)控cpu以及內(nèi)存使用情況之top命令(詳解)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-05-05shell腳本轉(zhuǎn)發(fā)80端口數(shù)據(jù)包給Node.js服務(wù)器
開(kāi)發(fā)基于Node.js的WEB應(yīng)用很方便,但是服務(wù)端口問(wèn)題很蛋疼,由于Linux內(nèi)核規(guī)定普通用戶只能使用大于1024的端口號(hào),所以使用普通用戶運(yùn)行Node.js服務(wù)就不能監(jiān)聽(tīng)80端口2014-03-03