Skip to content

Instantly share code, notes, and snippets.

@jesperronn
Created October 1, 2009 11:35
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 jesperronn/198914 to your computer and use it in GitHub Desktop.
Save jesperronn/198914 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# THis script looks for orphan image files in a GIT project
# For now, it looks for usages in the current source files via git grep
#
# usage:
# unused [foldername]
# unused ../images
require 'fileutils'
ARGV[0] ||= 'images'
puts "looking for unused images in folder: " + ARGV[0]
FileUtils.cd(ARGV[0], :verbose => true)
files = Dir['**/*.png', '**/*.gif', '**/*.jpg']
puts "found #{files.size} files:"
puts files.join(', ')
#puts Dir.glob("*")
puts '=====================verify current directory=============='
puts `pwd`
puts '=====================end verify============================'
puts
puts '=====================verify git ==========================='
git = `which git`.strip
puts "git command is found at '#{git}'"
puts '=====================end verify============================'
puts
puts '=====================verify git log works=================='
puts `git log -1 --oneline --stat`
puts '=====================end verify============================'
puts
puts '=====================verify git st works==================='
puts `git status`
puts "(exit code: #{$?.exitstatus})"
puts '=====================end verify============================'
puts
files[0..3].each do |f|
puts %(git grep #{f.strip})
print `git grep #{f.strip}`
puts " <---- this line should NOT be blank!"
puts " (exit code: #{$?})"
end
puts "TOTAL #{files.size} FILES"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment