satyr (owner)

Revisions

gist: 160204 Download_button fork
public
Public Clone URL: git://gist.github.com/160204.git
Embed All Files: show embed
ubiquity-mozrepl.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!ruby
unless $*[0]
  puts "Usage: ruby #$0 [-[ef]] input"
  puts ' -e: execute'
  puts ' -f: focus'
  exit 1
end
 
require 'net/telnet'
 
def mozexec js
  prompt = /^repl> /
  mozrepl = Net::Telnet.new 'Port'=> 4242, 'Prompt'=> prompt, 'Timeout'=> 5
  mozrepl.waitfor prompt
  mozrepl.cmd(js){|s| print s.sub prompt, '' }
  mozrepl.close
end
 
opt = $*[0] =~ /^-\w*/ ? $*.shift : ''
execu = opt[/e/i]
focus = opt[/f/i]
 
input = $*.join(' ').encode('utf-8').chars.map{|c| '\\u%04x' % c.ord }.join
code = "gUbiquity.#{execu ? 'execute' : 'preview'}('#{input}');";
code = "minimize(); restore(); #{code} focus();" if focus
 
mozexec "with(opener || top){ #{code} }"