Want more features on Pastebin? Sign Up, it's FREE!
Guest

Untitled

By: a guest on Apr 11th, 2010  |  syntax: Ruby  |  size: 1.04 KB  |  views: 184  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. $ cat bin/say
  2. #!/usr/bin/env ruby
  3.  
  4. class String
  5.   # return this string in qoutes
  6.   def quote
  7.     return '"' + self + '"'
  8.   end
  9.  
  10.   # copied from file lib/shellwords.rb, line 69
  11.   # escapes a string according to sh rules
  12.   def shellescape str = self
  13.     return "''" if str.nil? # added by nailor
  14.     # An empty argument will be skipped, so return empty quotes.
  15.     return "''" if str.empty?
  16.  
  17.     str = str.dup
  18.  
  19.     # Process as a single byte sequence because not all shell
  20.     # implementations are multibyte aware.
  21.     str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/n, "\\\\\\1")
  22.  
  23.     # A LF cannot be escaped with a backslash because a backslash + LF
  24.     # combo is regarded as line continuation and simply ignored.
  25.     str.gsub!(/\n/, "'\n'")
  26.  
  27.     return str
  28.   end
  29.  
  30.   def asciify
  31.     return self.tr("^A-Za-z0-9_.\-", "_")
  32.   end
  33. end
  34.  
  35. if ARGV.length < 1
  36.   STDERR.puts "need an argument"
  37.   Process.exit(-1)
  38. end
  39.  
  40. text = ARGV.join(" ")
  41.  
  42. text = text.shellescape
  43.  
  44. p text
  45. system "echo #{text} | espeak -v de --stdin --stdout | aplay"
clone this paste RAW Paste Data