Module: Antrapol::ToolRack::TerminalUtils

Defined in:
lib/toolrack/terminal_utils.rb

Instance Method Summary collapse

Instance Method Details

#tu_new_terminal(terminal, cmd) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
# File 'lib/toolrack/terminal_utils.rb', line 11

def tu_new_terminal(terminal, cmd)

  cmd = [cmd] if not cmd.is_a?(Array)

  case terminal
  when "terminator", "tilix"
    #`#{terminal} -x "#{cmd.join(" ")}"`
    `#{terminal} -e "bash -c '#{cmd.join(" ")}'" &`

  when "gnome-terminal"
    `#{terminal} -- bash -c "#{cmd.join(" ")}; exec bash"`

  when "iTerm2"
    `osascript -e \
         'tell application "iTerm"
         activate

         create window with default profile
         delay 0.5

         set currentWindow to current window

         tell current session of currentWindow
         write text "#{cmd.join(" ")}"
         end tell

         end tell'
    `
  when "Terminal" 
    `osascript -e \
         'tell application "Terminal"
         activate
         do script "#{cmd.join(" ")}"
         end tell'
    `

  else
    raise TerminalUtilsException, "Terminal '#{terminal}' not supported. Supported terminal are : #{tu_possible_terminal.join(", ")}" 
  end

end

#tu_possible_terminalObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/toolrack/terminal_utils.rb', line 53

def tu_possible_terminal
  avail = []
  if RuntimeUtils.on_linux?
    possible = [ "gnome-terminal","konsole","tilix", "terminator" ]
    possible.each do |app|
      avail << app if not File.which(app).nil?
    end
  elsif RuntimeUtils.on_windows?
    avail << "cmd.exe"
  elsif RuntimeUtils.on_mac?
    avail << "Terminal"
    avail << "iTerm2"
  end
  avail
end