Last active
August 29, 2015 14:04
-
-
Save aasmith/5dcc57aba80eae3b3823 to your computer and use it in GitHub Desktop.
eachdir - Run a command in each child directory.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby -w | |
# eachdir - Run a command in each child directory. | |
abort "need command" unless ARGV[0] | |
abort "quote the command" unless ARGV.size == 1 | |
def banner(path) | |
dirname, basename = File.split path | |
puts | |
puts "== #{basename} in #{dirname} ".ljust 80, "=" | |
puts | |
end | |
root = Dir.pwd | |
dirs = Dir.entries(root). | |
select { |ref| File.directory? ref }. | |
select { |dir| dir =~ /^[a-z]/i }. | |
map { |dir| File.join(root, dir) } | |
dirs.each do |dir| | |
Dir.chdir dir | |
banner dir | |
system ARGV[0] | |
end | |
Dir.chdir root |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment