Skip to content

Instantly share code, notes, and snippets.

@sgr-ksmt

sgr-ksmt/script.sh

Created Aug 22, 2016
Embed
What would you like to do?
Output percentage of languages between Swift and Objective-C.
#!/bin/bash
calc_percentage() {
echo "$1/$2*100" | bc -l | awk '{s=($0<0)?-1:1;print int($0*s*100+0.5)/100/s;}'
}
arr=($(cloc --exclude-dir=Pods,Carthage --include-lang=Swift,Objective\ C ./ | sed -e '1,5d' | sed 's/-//g' | sed 's/Objective C/ObjectiveC/g' | awk '{print $5}' | grep -v -e 'code' -e '^S*$'))
swift_files=${arr[0]}
objc_files=${arr[1]}
sum=${arr[2]}
swift_percent=$(calc_percentage $swift_files $sum)
objc_percent=$(calc_percentage $objc_files $sum)
echo "Swift: $swift_percent%, Objective-C: $objc_percent%"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment