Blame view

script/boxen-git-credential 1.1 KB
28d13c35c   John Barnette   Add script/boxen-...
1
2
  #!/usr/bin/ruby
  # Provide git credentials using Boxen's config.
f54871efa   Will Farrington   one dot oh
3
  unless command = ARGV[0]
28d13c35c   John Barnette   Add script/boxen-...
4
5
6
    this = File.basename $0
    abort "Usage: #{this} <get|store|erase>"
  end
28d13c35c   John Barnette   Add script/boxen-...
7
8
9
10
11
  require "pathname"
  
  # Put us where we belong, in the root dir of our boxen repo.
  
  Dir.chdir Pathname.new(__FILE__).realpath + "../.."
fc70b4b0a   John Barnette   Kill external BUN...
12
13
14
15
  # Because we can be called from inside other Ruby processes, unset any
  # `BUNDLE_` environment variables.
  
  ENV.keys.select { |k| /^BUNDLE_/i }.each { |k| ENV.delete k }
28d13c35c   John Barnette   Add script/boxen-...
16
17
18
  # Set up our local configuration, deps, and load path.
  
  load "config/basic.rb"
28d13c35c   John Barnette   Add script/boxen-...
19
20
21
  require "boxen/config"
  
  config = Boxen::Config.load
f54871efa   Will Farrington   one dot oh
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  input  = $stdin.read
  attrs  = Hash[input.split($/).map { |l| l.split("=") }]
  
  if command != "get" || attrs["host"] != "github.com"
    require "open4"
  
    fallback   = ENV["BOXEN_GIT_CREDENTIAL_FALLBACK"]
    fallback ||= "#{config.homedir}/homebrew/bin/git-credential-osxkeychain"
  
    status = Open4.popen4 fallback, *ARGV do |pid, stdin, stdout, stderr|
      stdin.write input
      stdin.puts
  
      $stdout.write stdout.read
    end
  
    exit status.exitstatus
  end
28d13c35c   John Barnette   Add script/boxen-...
40
41
42
  
  puts "username=#{config.login}"
  puts "password=#{config.password}"