Class: TmRb::Multiplexer

Inherits:
Object
  • Object
show all
Includes:
Exceptions
Defined in:
lib/tmrb.rb

Instance Method Summary collapse

Constructor Details

#initializeMultiplexer

Returns a new instance of Multiplexer.



10
11
12
# File 'lib/tmrb.rb', line 10

def initialize
  @sessions = []
end

Instance Method Details

#active_window(num) ⇒ Object

Set the active window in that session

Parameters:

  • num (Integer)

    the number of window which should be active in that tmux session



67
68
69
70
71
# File 'lib/tmrb.rb', line 67

def active_window(num)
  # the active window will always be set for the last defined session
  session = get_last_session
  session.active_window(num)
end

#new_session(options = {}) ⇒ Object

Creates a new tmux session

Parameters:

  • options (optional, Hash) (defaults to: {})

    options to create a tmux session with

Options Hash (options):

  • :session_name (String) — default: 'default'

    the name of the session itself

  • :window_name (String) — default: 'tab'

    the name of first window of the session

  • :command (String) — default: 'zsh'

    command which should be started in the first window of the session

Raises:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/tmrb.rb', line 21

def new_session(options={})

  options = { 
    :session_name => 'default',
    :window_name => 'tab',
    :command => 'zsh'
  }.update options

  if @sessions.find { |s| s.session_name == options[:session_name] }
    raise DuplicateSessionIdentifier , "Please do not reuse the session identifier. You used \"#{options[:session_name]}\" at least twice."
  end

  session = Session.new(options[:session_name], options[:window_name], options[:command])
  @sessions <<  session
  session
end

#new_window(options = {}) ⇒ Object

Creates a new tmux window

Parameters:

  • options (optional, Hash) (defaults to: {})

    options to create a tmux window with

Options Hash (options):

  • :name (String) — default: 'tab'

    the name of window

  • :command (String) — default: 'zsh'

    command which should be started in the window



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/tmrb.rb', line 43

def new_window(options={})

  options = { 
    :name => 'tab',
    :command => 'zsh'
  }.update options

  # windows will be attached to the last session defined
  session = get_last_session

  #if no sessions have been created, create a new one
  if session == nil
    say "Warning: No valid session found. Create a default one"
    session = new_session
  end
 
  #windows belong to a session
  session.add_window Window.new( options[:name] , options[:command] )

end

#start(process_info = {}) ⇒ Object

Start tmux

Parameters:

  • process_info (optional, Hash) (defaults to: {})

    a hash containing information about the tmux process to be started



97
98
99
100
101
102
# File 'lib/tmrb.rb', line 97

def start(process_info={})

  process_info[:cmd] = 'tmux'
  process_info[:status] = system(%Q{#{process_info[:cmd]} #{build_multiplexer_command_string} attach}) 

end