class Lab42::Tmux::Session
Attributes
commands[R]
configuration[R]
session_name[R]
window_number[R]
Public Class Methods
new(sess_name)
click to toggle source
# File lib/lab42/tmux/session.rb, line 29 def initialize sess_name @session_name = sess_name @window_number = 0 @commands = [] @configuration = $config || Config.new self.class.instance self end
Private Class Methods
instance(an_instance=nil)
click to toggle source
# File lib/lab42/tmux/session.rb, line 72 def instance an_instance=nil return @instance unless an_instance @instance = an_instance end
run()
click to toggle source
# File lib/lab42/tmux/session.rb, line 77 def run raise Lab42::Tmux::NoSessionDefined, "you need to define a session with `new_session` in your script" unless instance instance.run end
Public Instance Methods
config(&block)
click to toggle source
# File lib/lab42/tmux/session.rb, line 16 def config &block block.( configuration ) end
run(&block)
click to toggle source
# File lib/lab42/tmux/session.rb, line 20 def run &block return attach if running? create_session instance_exec( &block ) attach end
Private Instance Methods
attach()
click to toggle source
# File lib/lab42/tmux/session.rb, line 38 def attach command 'attach-session', '-t', session_name end
create_session()
click to toggle source
# File lib/lab42/tmux/session.rb, line 42 def create_session command 'source-file', File.join( ENV["HOME"], '.tmux.conf' ) # TODO: replace 'sh' with a configuration value command 'new-session', '-d', '-s', session_name, '-n', 'sh' command 'set-window-option', '-g', 'automatic-rename', 'off' unless configuration.window_automatic_rename goto configuration.project_home end
run_command(command)
click to toggle source
# File lib/lab42/tmux/session.rb, line 54 def run_command command case command when String Lab42::Tmux::Interface.command command when Array Lab42::Tmux::Interface.command( *command ) else instance_exec( &command ) end end
run_registered_commands()
click to toggle source
# File lib/lab42/tmux/session.rb, line 65 def run_registered_commands commands.each do | command | run_command command end end
running?()
click to toggle source
# File lib/lab42/tmux/session.rb, line 50 def running? Interface.query 'has-session', '-t', session_name end