Last active
December 16, 2015 03:59
-
-
Save jeremywrowe/5373873 to your computer and use it in GitHub Desktop.
Do you want to get onto your recent branchies easy? Here - ya - go. Create a new file named whatever you want, make it executable and put it in your path.
From there go to your favorite project that you are working on type in whatever you named the script, and you are off to the races.
This file contains 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 | |
trap("INT") { puts "\ncatch'ya later"; exit 0 } | |
output = `git for-each-ref --count=10 --sort=-committerdate refs/heads/ --format='%(refname:short)'` | |
branches = output.split("\n") | |
unless option = ARGV[0] | |
puts <<-MSG | |
You can use the number to the left of the branch name or | |
an ignorant best match guess can be made to select the branch | |
string that you type in. | |
MSG | |
branches.each_with_index do |branch, index| | |
puts "#{index}) #{branch}" | |
end | |
print "\n> " | |
option = gets.strip | |
end | |
if option =~ /^\d+$/ | |
`git checkout #{branches[option.to_i]}` | |
else | |
closest_matches = branches.select{|branch| branch.downcase.include? option.downcase } | |
if closest_matches.size > 0 | |
`git checkout #{closest_matches.first}` | |
else | |
puts "Did not find a branch name that included #{option.downcase}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment