Skip to content

Instantly share code, notes, and snippets.

@neoneye
Created July 17, 2014 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neoneye/c02ad9d07c19d34e0022 to your computer and use it in GitHub Desktop.
Save neoneye/c02ad9d07c19d34e0022 to your computer and use it in GitHub Desktop.
Count total number of lines in a project
def count_number_of_lines(path, suffix)
count = 0
Dir.chdir(path) do
cmd = 'find . -type f -name "*.SUFFIX" -print0 | xargs -0 cat | wc -l'
cmd.gsub!('SUFFIX', suffix)
result = `#{cmd}`
count = result.to_i
end
return count
end
desc "Count the number of lines in this project"
task :lines do
path_suffix_array = [
['app_ios/classes', 'm'],
['app_ios/classes', 'h'],
['app_ios/classes', 'swift'],
['server', 'erl'],
]
results = path_suffix_array.map do |path_suffix|
path, suffix = path_suffix
count_number_of_lines(path, suffix)
end
total_count = results.inject(0) { |accum, count| accum + count }
results.zip(path_suffix_array).each do |count, path_suffix|
path, suffix = path_suffix
puts " %6d %-18s .%s" % [count, path, suffix]
end
puts "---------------------------------"
puts " %6d total" % total_count
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment