#!/usr/bin/env ruby # read-eval loop: repeatedly run a fixed command, appending each input line as arguments. # supports basic line editing. # arguments: command argument ... # exit: ctrl+d or ctrl+c (sigint). # examples: "repl find -name" require "readline" require "open3" base = ARGV[0].to_s fixed = (ARGV[1..] || []).map { |a| %("#{a}") }.join(" ") prefix = [base, fixed].reject(&:empty?).join(" ") trap("INT") { exit 0 } while (line = Readline.readline("> ", true)) cmd = (prefix + " " + line).strip out, _, _ = Open3.capture3(cmd) STDOUT.write(out.rstrip + "\n") end