-
Notifications
You must be signed in to change notification settings - Fork 2
/
.irbrc
74 lines (57 loc) · 1.64 KB
/
.irbrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# something to play with https://nts.strzibny.name/improving-irb-with-custom-irbrc/
require 'irb/completion'
require 'irb/ext/save-history'
require 'rubygems'
require 'pp'
ARGV.concat [ "--readline", "--prompt-mode", "simple" ]
IRB.conf[:VERBOSE] = true
IRB.conf[:SAVE_HISTORY] = 10000
IRB.conf[:HISTORY_FILE] = "#{ENV['HOME']}/.ruby_history"
module IRB
def self.start_session(binding)
IRB.setup(nil)
workspace = WorkSpace.new(binding)
if @CONF[:SCRIPT]
irb = Irb.new(workspace, @CONF[:SCRIPT])
else
irb = Irb.new(workspace)
end
@CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
@CONF[:MAIN_CONTEXT] = irb.context
trap("SIGINT") do
irb.signal_handle
end
catch(:IRB_EXIT) do
irb.eval_input
end
end
end
module Kernel
def self.irb
IRB.start_session(Kernel.binding)
end
end
module Balls
def remote_execute(host, *commands)
commands = commands.flatten.map(&:chomp)
ssh = Net::SSH.start(host, `whoami`.chomp)
channel = ssh.open_channel do |channel|
channel.exec("bash -l") do |ch, success|
ch.on_data { |_, data| STDOUT.print data }
ch.on_extended_data { |_, _, data| STDERR.print data }
ch.on_close { STDOUT.print "connection closed." }
commands.each do |c|
STDOUT.print "#{c}\n"
ch.send_data "#{c}\n"
end
ch.send_data("exit\n")
end
end
channel.wait
return true
end
end
# Give ourselves some balls.
class << self
include Balls
end