Sean's Ruby script to improve tutorial
authorKyle Spaans <kspaans@uwaterloo.ca>
Wed, 29 Jun 2011 17:35:39 +0000 (13:35 -0400)
committerKyle Spaans <kspaans@uwaterloo.ca>
Wed, 29 Jun 2011 17:35:39 +0000 (13:35 -0400)
The Ruby script does the interactive part of the tutorial in a more interesting
way then the original bash script does. Plus it moves the script into a seperate
file.

prompt.rb [new file with mode: 0755]
script [new file with mode: 0644]

diff --git a/prompt.rb b/prompt.rb
new file mode 100755 (executable)
index 0000000..9ab24f4
--- /dev/null
+++ b/prompt.rb
@@ -0,0 +1,29 @@
+#!/usr/bin/env ruby
+def expect(cmd)
+  fail_count = 0
+  while true
+    print '> '
+    input = gets.chomp
+    if input.match cmd
+      print '#'
+      puts  `#{input}`
+      break
+    else
+      if fail_count < 3
+        puts "oops, try that again"
+        fail_count += 1
+      else
+        puts "alright, fine. just type '#{cmd}'"
+      end
+    end
+  end
+end
+File.open('script').lines.to_a.each do |line|
+  if line.match /cmd: (.*)/
+    expect $1
+  else
+    puts line
+  end
+end
diff --git a/script b/script
new file mode 100644 (file)
index 0000000..3d62818
--- /dev/null
+++ b/script
@@ -0,0 +1,4 @@
+hi there!
+why don't you check the system's uptime?
+cmd: uptime
+good job