Skip to content

Instantly share code, notes, and snippets.

@trevorcreech
Created August 12, 2017 01:06
Show Gist options
  • Save trevorcreech/3dd4b9ee71cb3725031d5e9fc6a6437e to your computer and use it in GitHub Desktop.
Save trevorcreech/3dd4b9ee71cb3725031d5e9fc6a6437e to your computer and use it in GitHub Desktop.
#!/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