Skip to content

Instantly share code, notes, and snippets.

@aasmith
Last active August 29, 2015 14:04
Show Gist options
  • Save aasmith/5dcc57aba80eae3b3823 to your computer and use it in GitHub Desktop.
Save aasmith/5dcc57aba80eae3b3823 to your computer and use it in GitHub Desktop.
eachdir - Run a command in each child directory.
#!/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