Sha256: 506fd3d4fd880461dcdc9fbc127a00dfcee5bbf58840a92d32b4817022ed09e2

Contents?: true

Size: 1.35 KB

Versions: 7

Compression:

Stored size: 1.35 KB

Contents

#!/usr/bin/env ruby

lib = File.expand_path('../lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'git/switcher'

def putm(message, color = :to_s)
  return if message.strip.empty?

  puts '', Rainbow(message).send(color)
  print Rainbow('Press ⏎ to continue ... ').italic
  $stdin.gets
end

repo = Rugged::Repository.new(Dir.pwd)
menu = Git::Switcher::Menu.for(repo)

# (optional) script to run after every checkout
switcher = File.join(repo.workdir, '.switcher')

loop do
  print "\e[H\e[2J", menu, "\n", "\n" # clear the screen first (^L)

  if (default_menu_item = menu.default_menu_item)
    default_shortcut = format('⏎ [%2s]', default_menu_item.shortcut)
    print Rainbow(default_shortcut).bold.steelblue, ' '
  end
  print "\t", Rainbow('your selection =>').steelblue, ' '

  response = begin
               $stdin.gets&.strip
             rescue Interrupt
               nil
             end

  break unless response # ^C and ^D

  menu_item = if response.empty?
                default_menu_item
              else
                menu[response]
              end

  next unless menu_item

  err_msg = `2>&1 git checkout --quiet #{menu_item.reference.name}`
  if $CHILD_STATUS.success? && File.executable?(switcher)
    cmd_msg = `2>&1 #{switcher}`
    putm(cmd_msg, :green)
  else
    putm(err_msg, :red)
  end
end

# That's all Folks!

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
git-switcher-1.0.6 exe/git-switcher
git-switcher-1.0.5 exe/git-switcher
git-switcher-1.0.4 exe/git-switcher
git-switcher-1.0.3 exe/git-switcher
git-switcher-1.0.2 exe/git-switcher
git-switcher-1.0.1 exe/git-switcher
git-switcher-1.0.0 exe/git-switcher