June 11 meeting notes on Unix bits
[kspaans/mterry/.git] / prompt.rb
1 #!/usr/bin/env ruby
2  
3 def expect(cmd)
4   fail_count = 0
5   while true
6     print '> '
7     input = gets.chomp
8     if input.match cmd
9       print '#'
10       puts  `#{input}`
11       break
12     else
13       if fail_count < 3
14         puts "oops, try that again"
15         fail_count += 1
16       else
17         puts "alright, fine. just type '#{cmd}'"
18       end
19     end
20   end
21 end
22  
23 File.open('script').lines.to_a.each do |line|
24   if line.match /cmd: (.*)/
25     expect $1
26   else
27     puts line
28   end
29 end