Skip to content

Instantly share code, notes, and snippets.

@Sixeight
Created October 24, 2012 05:42
Show Gist options
  • Save Sixeight/3944254 to your computer and use it in GitHub Desktop.
Save Sixeight/3944254 to your computer and use it in GitHub Desktop.
# coding: utf-8
require 'readline'
branches = `git branch -r`
branches = branches.split(/\n/).map {|b| b.strip }
branches.shift
branches.delete_if {|branch| branch == 'origin/master' }
candidates = %w[check log grep open delete tag skip exit]
candidates += branches
Readline.completion_proc = lambda {|word|
candidates.grep(%r|\A(origin/)?#{Regexp.quote(word)}|)
}
def git(cmd, *args)
system 'git', cmd, *args
end
total_count = branches.size
branches.shuffle.each_with_index do |branch, idx|
branch_name = branch.gsub(%r|origin/|, '')
cmd = ''
loop do
puts 'INSPECT: [c]heck, [l]og, [g]rep, [o]pen'
puts ' MANAGE: [d]elete, [t]ag, [s]kip, [e]xit'
puts
puts "[#{branch}]"
puts "Do you want? (%d/%d)" % [idx+1, total_count]
cmd = Readline.readline('> ', true)
case cmd
when /\A!/
script = cmd.gsub(/\A!\s*/, '')
system script
when /\Ad/
yes_or_no = Readline.readline('Are you sure? [yN]: ')
if /\Ay/ =~ yes_or_no
git 'push', 'origin', ":#{branch_name}"
git 'branch', '-D', branch_name
break
end
when /\Ao/
# open github page
when /\Al/
git 'log', branch
when /\Ac/
git 'log', 'master', '--grep', branch_name
when /\As/
puts "skipping #{branch}..."
break
when /\Ae/
puts 'bye'
exit
when /\Ag/
_, keyword = cmd.split(/\s/, 2)
git 'log', 'master', '--grep', keyword
when /\At/
_, name = cmd.split(/\s/)
name = branch_name if name.nil?
git 'tag', name, branch
git 'push', 'origin', name
end
puts
end
puts
end
puts 'bye'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment