gits 1.1 KB

1234567891011121314151617181920212223242526
  1. #!/usr/bin/env ruby
  2. USAGE = "USAGE:\n" +
  3. "\tgits [ <base-dir> ]\n\n" +
  4. "DESCRIPTION:\n" +
  5. "\tthis script displays all git repositories in and under the specified directory\n" +
  6. "\talong with disk usage for the repo both with and without the working tree"
  7. DU_CMD = 'du --summarize --human-readable'
  8. !(puts USAGE) and exit unless ARGV[0].nil? || (File.directory? ARGV[0])
  9. search_path = (ARGV[0] || `pwd`).gsub "\n" , ''
  10. git_dirs = `find #{search_path} -type d -name .git`.split "\n"
  11. n_repos = git_dirs.size
  12. puts "#{n_repos} git repo#{(n_repos != 1) ? "s" : ""} found under #{search_path}"
  13. git_dirs.each do | git_dir |
  14. working_dir = git_dir.gsub /(\/.git$)/ , ''
  15. total_bytes = (`#{DU_CMD} #{working_dir}`.split "\t")[0]
  16. raw_bytes = (`#{DU_CMD} #{git_dir }`.split "\t")[0]
  17. puts "#{working_dir} #{total_bytes}B (#{raw_bytes}B raw)"
  18. end