Skip to content

Instantly share code, notes, and snippets.

@trevorcreech
Created Aug 12, 2017
Embed
What would you like to do?
#!/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