Skip to content

Instantly share code, notes, and snippets.

@brentsimmons
Created January 1, 2012 04:25
Show Gist options
  • Save brentsimmons/1546249 to your computer and use it in GitHub Desktop.
Save brentsimmons/1546249 to your computer and use it in GitHub Desktop.
Find Mercurial repositories and print status
#!/usr/bin/env ruby -wKU
# Prints the directory names and hg status output for any Mercurial
# repositories where hg status returns something non-nil.
#
# Assumes everything is in a Projects directory in your home folder.
# 12/31/2011 Brent Simmons
require 'find'
require 'open3'
homeDirectory = ENV["HOME"]
projectsDirectory = homeDirectory + "/Projects"
Find.find(projectsDirectory) do |path|
if File.basename(path) == '.hg'
workingDirectory = File::dirname(path)
Dir.chdir(workingDirectory)
status = Open3.popen3("hg status")[1].read
if status == "" then next end
print("\n#{workingDirectory}\n")
print status
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment