Skip to content

Instantly share code, notes, and snippets.

@hitode909
Created December 28, 2016 03:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hitode909/40c7c46019df45e23ff665cdf8b1ba09 to your computer and use it in GitHub Desktop.
Save hitode909/40c7c46019df45e23ff665cdf8b1ba09 to your computer and use it in GitHub Desktop.
# replace HERE interactive, execute command.
# for example: ruby interactive.rb expr HERE + HERE + HERE
require 'readline'
require 'shellwords'
HERE = /HERE/
def read_input
Readline.readline("> ", true)
end
command_template = ARGV
loop {
command = command_template.clone
command.map!{|fragment|
fragment.gsub(HERE) {
puts "command: #{command.join(' ')}"
read_input
}
}
puts "execute #{command.join(' ')}? (y/N)"
next unless read_input == 'y'
system *command
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment