Class: Consular::AnotherGnomeTerminal

Inherits:
Core
  • Object
show all
Defined in:
lib/consular/another-gnome-terminal.rb,
lib/consular/another-gnome-terminal/version.rb

Defined Under Namespace

Modules: Version

Constant Summary collapse

TERMINAL_CMD =
"gnome-terminal"
VERSION =
[
  Version::MAJOR, Version::MINOR, Version::PATCH
].compact.join('.')

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ AnotherGnomeTerminal

Returns a new instance of AnotherGnomeTerminal.



21
22
23
24
# File 'lib/consular/another-gnome-terminal.rb', line 21

def initialize(path)
  super
  @tabidx = nil
end

Class Method Details

.platformObject



11
12
13
# File 'lib/consular/another-gnome-terminal.rb', line 11

def platform
  RUBY_PLATFORM
end

.valid_system?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/consular/another-gnome-terminal.rb', line 15

def valid_system?
  !!(platform =~ /linux/ && !`which #{TERMINAL_CMD}`.empty?)
end

Instance Method Details

#get_name_cmd_option(item) ⇒ Object



30
31
32
33
34
# File 'lib/consular/another-gnome-terminal.rb', line 30

def get_name_cmd_option item
  options = item[:options] || {}
  name = options[:name]
  name ? "-t '#{name}'" : ""
end

#process!Object

Raises:

  • (NotImplementedError)


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
# File 'lib/consular/another-gnome-terminal.rb', line 36

def process!
  windows = @termfile[:windows]
  default = windows.delete('default')

  raise NotImplementedError, "Tabs aren't supported for current window" \
    if default[:tabs].keys.count > 1

  #run commands from default section
  commands = default[:tabs].values.first[:commands] || []
  STDOUT.puts `#{commands.join('; ')}` if commands.any?

  windows.each do |wname, window|
    cmd = [ TERMINAL_CMD ]
    cmd << get_name_cmd_option(window)

    before = window[:before]
    window[:tabs].each do |tname, tab|
      commands = tab[:commands]
      commands = before + commands if before

      cmd << "--tab #{get_name_cmd_option(tab)} -e 'bash -c '\\''#{commands.join('; ')}; exec bash'\\'"
    end
    
    `#{cmd.join(' ')}`
  end
end

#setup!Object

Raises:

  • (NotImplementedError)


26
27
28
# File 'lib/consular/another-gnome-terminal.rb', line 26

def setup!
  raise NotImplementedError
end