-
-
Save trevorcreech/3dd4b9ee71cb3725031d5e9fc6a6437e to your computer and use it in GitHub Desktop.
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 | |
require 'io/console' | |
begin | |
require 'colorize' | |
rescue LoadError | |
puts 'Running without colors. Install colorize gem for colors' | |
end | |
branches = `git branch --sort=-committerdate | head -n 10`.lines | |
COLORS = [ | |
:light_red, | |
:yellow, | |
:green, | |
:cyan, | |
:magenta, | |
].freeze | |
max_length = branches.map(&:length).max | |
branches.each_with_index do |branch, idx| | |
color = COLORS[idx % COLORS.count] | |
puts "#{idx}: #{branch.strip.ljust(max_length)} #{idx}".colorize(color).bold | |
end | |
choice = STDIN.getch | |
if choice !~ /[0-9]/ | |
exit 0 | |
end | |
system("git checkout #{branches[choice.to_i]}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment