Class: JustTmux

Inherits:
Object
  • Object
show all
Defined in:
lib/just-tmux.rb

Overview

2019 Nov 06: Bug fix: The sleep variable is now sleepx 2019 Nov 04: Bug fix: The sleep variable is now explicitly set to a float 2018 Aug 05: Minor modification: Changed to using Dynarex#to_a instead of Dynarex#to_h. 2017 Jan 07: Added post_shell to allow a command to execute after the

new shell has been created e.g. rvm  use 2.4.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dx, debug: false) ⇒ JustTmux

example raw dynarex file:

config=<<EOF <?dynarex schema=“tmux[session, shell, default_dir]/window(command, name, dir)”?> session: fun shell: bash default_dir: ~

lis pwd home /home/james/ruby EOF



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
73
# File 'lib/just-tmux.rb', line 33

def initialize(dx, debug: false)
  
  @debug = debug

  dynarex = dx.is_a?(Dynarex) ? dx : Dynarex.new(dx)

  puts ('dynarex.summary: ' + dynarex.summary.inspect).debug if @debug
  
  shell = if dynarex.summary[:shell].nil? or 
      dynarex.summary[:shell].empty? then
  
    dynarex.summary[:shell] = 'bash' 
    
  else
    dynarex.summary[:shell]
  end
  
  puts 'shell: ' + shell.inspect if @debug
  post_shell = CGI.unescape(dynarex.summary[:post_shell].to_s) || ''
  default_dir = File.expand_path dynarex.summary[:default_dir] || '~'
  session_name = dynarex.summary[:session] || '0'
  @detach = dynarex.summary[:detach].to_s.downcase == 'false' ? \
      false : true
  puts ('@detach: ' + @detach.inspect).debug if @debug

  h = dynarex.to_a.map do |x| 
    x[:name]  = shell        if x[:name].nil?  or  x[:name].empty?
    x[:dir]   = default_dir  if x[:dir].nil?   or  x[:dir].empty?
    x[:sleepx] = 0            if x[:sleepx].nil?
    x
  end
  
  @to_s = new_session(session_name, h[0][:name], shell, post_shell) +  
      send_keys("cd #{h[0][:dir]} && " + h[0][:command]) + 
      wait(h[0][:sleepx]) + 
    h[1..-1].map do |x| 
      new_window(x[:name],  shell, post_shell) + 
          send_keys("cd #{x[:dir]} && " + x[:command]) + wait(x[:sleepx]) 
      end.join

end

Instance Attribute Details

#to_sObject (readonly)

Returns the value of attribute to_s.



18
19
20
# File 'lib/just-tmux.rb', line 18

def to_s
  @to_s
end