Class: Superterm
- Inherits:
-
Object
show all
- Defined in:
- lib/superterm.rb
Defined Under Namespace
Classes: Gui, Unix_socket
Constant Summary
collapse
- CONFIG =
{
:path => "#{Knj::Os.homedir}",
:sock_path => "#{Knj::Os.homedir}/.superterm/sock",
:run_path => "#{Knj::Os.homedir}/.superterm/run"
}
Class Method Summary
collapse
Class Method Details
.const_missing(name) ⇒ Object
20
21
22
23
24
|
# File 'lib/superterm.rb', line 20
def self.const_missing(name)
require "#{File.dirname(__FILE__)}/superterm_#{name.to_s.downcase}.rb"
raise "Still not defined: '#{name}'." if !Superterm.const_defined?(name)
return Superterm.const_get(name)
end
|
.start ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/superterm.rb', line 26
def self.start
do_start = false
FileUtils.touch(CONFIG[:run_path]) if !File.exists?(CONFIG[:run_path])
File.open(CONFIG[:run_path]) do |fp|
fp.flock(File::LOCK_EX)
pid = File.read(CONFIG[:run_path]).to_i
if pid <= 0 or !Knj::Unix_proc.pid_running?(pid)
do_start = true
File.open(CONFIG[:run_path], "w") do |fp_w|
fp_w.write Process.pid
end
Kernel.at_exit do
File.unlink(CONFIG[:run_path])
end
end
end
if do_start
win_main = Superterm::Gui::Win_main.new
Superterm::Unix_socket.new(:win_main => win_main)
Gtk.main
else
cmd = nil
ARGV.each do |val|
if match = val.match(/^--cmd=(.+)$/)
cmd = match[1]
break
else
$stderr.puts "Unknown argument: '#{val}'."
exit
end
end
if cmd
puts "Executing command through sock: #{cmd}"
require "socket"
UNIXSocket.open(CONFIG[:sock_path]) do |sock|
sock.puts(cmd)
end
end
end
end
|