summaryrefslogtreecommitdiff
path: root/common/bin/rb
blob: 980016b674aefe76de04d86937bc0216e6bcac88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/usr/bin/ruby
# Taken from https://github.com/thisredone/rb

File.join(Dir.home, '.rbrc').tap { |f| load f if File.exist?(f) }

def execute(_, code)
  puts _.instance_eval(&code)
rescue Errno::EPIPE
  exit
end

single_line = ARGV.delete('-l')
code = eval("Proc.new { #{ARGV.join(' ')} }")
single_line ? STDIN.each { |l| execute(l.chomp, code) } : execute(STDIN.each_line, code)