Class: Xing::Managers::Tmux
- Inherits:
-
Object
- Object
- Xing::Managers::Tmux
- Includes:
- Caliph::CommandLineDSL
- Defined in:
- lib/xing/managers/tmux.rb
Direct Known Subclasses
Constant Summary collapse
- MINIMUM_WINDOW_COLUMNS =
75
- MINIMUM_WINDOW_LINES =
18
Instance Attribute Summary collapse
-
#shell ⇒ Object
readonly
Returns the value of attribute shell.
Class Method Summary collapse
Instance Method Summary collapse
- #copied_env_vars ⇒ Object
- #default_env ⇒ Object
- #env_string ⇒ Object
- #existing? ⇒ Boolean
-
#initialize(shell = nil) ⇒ Tmux
constructor
A new instance of Tmux.
- #rake_command(task) ⇒ Object
- #session_env ⇒ Object
- #tmux(*cmd) ⇒ Object
- #tmux_exe ⇒ Object
- #wait_all ⇒ Object
Constructor Details
Instance Attribute Details
#shell ⇒ Object (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
23 24 25 |
# File 'lib/xing/managers/tmux.rb', line 23 def available? shell.run("which", "tmux").succeeds? end |
.shell ⇒ Object
19 20 21 |
# File 'lib/xing/managers/tmux.rb', line 19 def shell @shell ||= Caliph.new end |
Instance Method Details
#copied_env_vars ⇒ Object
38 39 40 |
# File 'lib/xing/managers/tmux.rb', line 38 def copied_env_vars %w{PORT_OFFSET GEM_HOME GEM_PATH} end |
#default_env ⇒ Object
42 43 44 |
# File 'lib/xing/managers/tmux.rb', line 42 def default_env {"PORT_OFFSET" => 0} end |
#env_string ⇒ Object
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
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_env ⇒ Object
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_exe ⇒ Object
28 29 30 |
# File 'lib/xing/managers/tmux.rb', line 28 def tmux_exe @tmux_exe ||= shell.run("which", "tmux").stdout.chomp end |
#wait_all ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/xing/managers/tmux.rb', line 63 def wait_all path = File.(@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 |