Inside the pty
standard library module (no gems needed here) is an inner module you can require
called expect
. It will add an expect method to IO.
You probably want something like this:
require 'pty'
require 'expect'
PTY.spawn "git add -p" do |r, w, pid|
w.sync = true
r.expect ']? ' do |got|
puts got
puts 'responding with q'
w.write "q\r"
puts r.expect "\n", 9
end
end