[TxMt] Re: Properly escaping characters in ruby script

Ian Duncan iand675 at gmail.com
Wed Apr 8 21:37:02 UTC 2009


On Apr 8, 2009, at 4/8/093:05 PM, Allan Odgaard wrote:
>
> If this is a TextMate command you can do:
>
>     #!/usr/bin/env ruby
>     require "#{ENV['TM_SUPPORT_PATH']}/lib/escape"
>
>     arg = STDIN.read
>     arg.chomp!
>     system("pointfree #{e_sh arg}")

Ok, that helped some, but I ended up using e_as instead as the  
appropriate method. However, I still can't get it to escape backticks  
properly. Here's the script now:

#!/usr/bin/env ruby
     require "#{ENV['TM_SUPPORT_PATH']}/lib/escape"
	arg = STDIN.read
	arg.chomp!
	arg = e_as arg
	arg.gsub!("\`", "\\`")
	puts("pointfree \"" + arg + "\"")

The puts is just for debugging purposes. When I run this command on  
the selected text:

\x y -> x `div` y

I am hoping to get:

pointfree "\\x y -> x \`div\` y"

But I get this instead:

pointfree "\\x y -> x \\x y -> x div\\x y -> x `div y"




More information about the textmate mailing list