From c7eda7c92e5430ba23fd65b99028106147690224 Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Fri, 27 Nov 2009 08:43:00 -0800 Subject: [PATCH] [NEW] find-git-repos.rb, operates on ~/Projects right now. --- find-git-repos.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 find-git-repos.rb diff --git a/find-git-repos.rb b/find-git-repos.rb new file mode 100755 index 0000000..fbedea8 --- /dev/null +++ b/find-git-repos.rb @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby + +HomePath = File.expand_path('~') # better way to do this? +ProjectsPath = File.join(HomePath, 'Projects') + +def git_repos_in(path, recurse=true) + dirs = Dir[File.join(path, '*')].select do |path| + File.directory?(path) + end + if recurse + dirs.map do |path| + # add subdirs to the list but ignore subdirs of git repos + [path] + (git_repo?(path) ? [] : git_repos_in(path, true)) + end.flatten + else + dirs + end.select { |path| git_repo?(path) } +end + +def git_dir_in(path) + gitpath = File.join(path, '.git') + File.exists?(gitpath) ? gitpath : nil +end + +alias git_repo? git_dir_in + +git_repos_in(ProjectsPath).each do |path| + puts path +end \ No newline at end of file