Skip to content

Instantly share code, notes, and snippets.

@mikfreedman
Last active September 20, 2017 03:10
Show Gist options
  • Save mikfreedman/e092e84bed648f4e8408693d8b2b36c6 to your computer and use it in GitHub Desktop.
Save mikfreedman/e092e84bed648f4e8408693d8b2b36c6 to your computer and use it in GitHub Desktop.
Use fly with a temporary flyrc - useful for situations where you absolutely positively want your session to be temporary
#!/usr/bin/env ruby
# -*- mode: ruby -*-
# # vi: set ft=ruby :
require 'tmpdir'
class Input
attr_reader :get_method
def initialize(prompt)
require 'readline'
@get_method = ->() { Readline.readline(prompt, true) }
rescue LoadError
@get_method = -> () { print(prompt); gets }
end
def get
get_method.call.squeeze(" ").strip
end
end
class Repl
def initialize(prompt, env_vars, executable)
@env_vars = env_vars
@executable = executable
@input = Input.new(prompt)
end
def run
while buf = @input.get
system(@env_vars, @executable, buf)
end
end
end
WELCOME_MESSAGE = <<WELCOME
Welcome to temp-fly. This script starts fly with a temporary configuration, you may login like so:
`login -t target --concourse-url https://concourse.example.com --team-name team-name`
WELCOME
Dir.mktmpdir do |home|
puts WELCOME_MESSAGE
Repl.new("temp-fly> ", { "HOME" => home }, 'fly').run
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment