Recently, I used Bash to write a svn-based code statistics Tool. You can specify the statistics directory. The default recursive statistics subdirectory is used.
Currently, the specified directory is not blocked. Ha code is rough. But let's get it first.
#! /Bin/bash -#"""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""" "" # file: lines. sh ## usage :. /lines. sh [dir] # Author: William # Description: svn-based code submission statistics Tool # Email: lilijreey@126.com # options: --- # created: 06/05/2012 12:49:20 pm CST #""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""" "Set-O nounset # Treat unset variables as an error # post-charge Files_type = "*. cpp *. H *. Lua" # The person to be counted. Here, the person to be counted is written and separated by spaces. Ha is not smart. Declare-r coder_list = "coder1 coder2" declare-I coder1declare-I coder2declare-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 shield some dir files not written yet # todo other way get path not with/end getpath () {# debug # echo dir_name :$ {dir_name} # echo base_name :$ {base_name} if [$ dir_name = "/"] | [$ base_nam E = "/"]; thenwork_path = "/" elsework_path =$ {dir_name}/$ {base_name} fi} statistic_codelines () {if [-z "$1"]; thenecho "error statistic_codelines not argument" returnfilocal pwd_length =$ {# PWD} echo "------------------------" Echo "$ {PWD}" for coder in $ coder_list; dolocal num =$ (echo "$1" | grep $ {coder} | WC-l) ($ {coder} + = num )) if [$ num-Ne 0]; thenprintf "% 10 S | %-7d \ n" $ {coder} $ numfidoneecho "------------------------"} # Init check argument set work_pathinit_work_path () {if [$ #-EQ 1]; thenif [$1 = "-h"]; then # Is helpecho-e "$ usage" Elif [-d $1]; thendir_name =$ (dirname $ {1}) base_name =$ (basename $ {1}) getpath; elseecho-e "An invailed argument" echo-e "use-H get help. "Exit $ e_invailed_argufifi} # Check work_pathcheck_work_path () {if [-Z $ work_path] | [! -D $ work_path]; thenexit $ e_badpath; FI} # Enter work_pathenter_work_path () {CD $ {work_path} if [! $? ]; Thenecho "can not enter $ {work_path}" fi} # Check work_pat is a SVN diris_svn_dir () {(# Check if current DIR is asvn dirsvn info &>/dev/nullexit $ ?) Return $ ?} Action () {local dir_name =. local base_name = Local work_path = $ dir_nameinit_work_path $ worker # Todo can't enter # echo "Now dir: $ PWD, old dir $ oldpwd" is_svn_dir # todo to next dirlocal ret = $? If [$ ret-Ne 0] thenecho-e "Current dir \" $ {work_path} \ "not a SVN dir. "Exit $ e_not_svn_dirfi # Get source fileslocal 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" filocal sub_dirs = $ (find-maxdepth 1-type D-name "[^.] * "2>/dev/null) If [-N "$ sub_dirs"]; thenfor dir in $ sub_dirs; doaction "$ dir" doneficd ..} total () {echo "-------- totoal ----------" Echo "name | lines" Echo "--------------------------" for coder in $ coder_list; doif [$ {! Coder}-Ne 0]; thenprintf "% 10 S | %-7d \ n" $ {coder }$ {! Coder} fidoneecho "------------------------"} # mainecho "----- start statistics. Please wait..." Action $1 totalexit 0