Skip to content

Instantly share code, notes, and snippets.

@squarism
Created October 24, 2012 02:15
Show Gist options
  • Save squarism/3943329 to your computer and use it in GitHub Desktop.
Save squarism/3943329 to your computer and use it in GitHub Desktop.
Update All Git Vendor Repositories
#!/usr/bin/env ruby
# UPDATE ALL THE THINGS!
# go into each all the git projects and do a `git pull`
# this is mainly used to update apps which use git to deliver updates
# for example, rbenv & vim plugins
# change this here thing-o below. use an asterisk glob for a bunch of submodules.
projects = %w(
~/.vim/bundle/*
~/.oh-my-zsh
~/.rbenv
~/.rbenv/plugins/*
)
def git_pull(path)
git_output = `cd #{path} && git pull`
status = git_output.split("\n").last
puts "#{path.split("/").last}: \033[33m#{status}\033[0m"
end
def sub_dirs_from(path)
# we need to replace the tilde with HOME if the path has globs/stars
dir = path.gsub /^\~/, ENV['HOME']
Dir.glob(dir)
end
projects.each do |proj|
# if a path ends in * then we need to go into each one and do a git pull
if proj.match /\*$/
sub_dirs_from(proj).each do |path|
git_pull path
end
# otherwise, just do a git pull
else
git_pull proj
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment