Class: Xing::Managers::Tmux

Inherits:
Object
  • Object
show all
Includes:
Caliph::CommandLineDSL
Defined in:
lib/xing/managers/tmux.rb

Direct Known Subclasses

TmuxPane, TmuxWindow

Constant Summary collapse

MINIMUM_WINDOW_COLUMNS =
75
MINIMUM_WINDOW_LINES =
18

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shell = nil) ⇒ Tmux

Returns a new instance of Tmux.



11
12
13
14
15
# File 'lib/xing/managers/tmux.rb', line 11

def initialize(shell=nil)
  @shell = shell || Tmux.shell
  @first_child = true
  @extra_config_path='~/.lrd-dev-tmux.conf'
end

Instance Attribute Details

#shellObject (readonly)

Returns the value of attribute shell.



16
17
18
# File 'lib/xing/managers/tmux.rb', line 16

def shell
  @shell
end

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/xing/managers/tmux.rb', line 23

def available?
  shell.run("which", "tmux").succeeds?
end

.shellObject



19
20
21
# File 'lib/xing/managers/tmux.rb', line 19

def shell
  @shell ||= Caliph.new
end

Instance Method Details

#copied_env_varsObject



38
39
40
# File 'lib/xing/managers/tmux.rb', line 38

def copied_env_vars
  %w{PORT_OFFSET GEM_HOME GEM_PATH}
end

#default_envObject



42
43
44
# File 'lib/xing/managers/tmux.rb', line 42

def default_env
  {"PORT_OFFSET" => 0}
end

#env_stringObject



53
54
55
56
57
# File 'lib/xing/managers/tmux.rb', line 53

def env_string
  session_env.map do |envpair|
    envpair.join("=")
  end.join(" ")
end

#existing?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/xing/managers/tmux.rb', line 75

def existing?
  !(ENV['TMUX'].nil? or ENV['TMUX'].empty?)
end

#rake_command(task) ⇒ Object



59
60
61
# File 'lib/xing/managers/tmux.rb', line 59

def rake_command(task)
  "env #{env_string} bundle exec rake #{task}"
end

#session_envObject



46
47
48
49
50
51
# File 'lib/xing/managers/tmux.rb', line 46

def session_env
  Hash[copied_env_vars.map do |varname|
    varvalue = ENV[varname] || default_env[varname]
    [varname, varvalue] unless varvalue.nil?
  end.compact]
end

#tmux(*cmd) ⇒ Object



32
33
34
35
36
# File 'lib/xing/managers/tmux.rb', line 32

def tmux(*cmd)
  command = cmd(tmux_exe, *cmd)
  puts command.string_format
  shell.run(command).stdout.chomp
end

#tmux_exeObject



28
29
30
# File 'lib/xing/managers/tmux.rb', line 28

def tmux_exe
  @tmux_exe ||= shell.run("which", "tmux").stdout.chomp
end

#wait_allObject



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/xing/managers/tmux.rb', line 63

def wait_all
  path = File.expand_path(@extra_config_path)
  if File.exist?(path)
    puts "Loading #{path}"
    tmux "source-file #{path}"
  else
    puts "No extra config found at #{path}"
  end

  tmux "attach-session -d" unless existing?
end