class Tmux::Session

A session is a single collection of pseudo terminals under the management of {Tmux tmux}. Each session has one or more {Window windows} linked to it. A {Window window} occupies the entire screen and may be split into rectangular {Pane panes}, each of which is a separate pseudo terminal (the pty(4) manual page documents the technical details of pseudo terminals). Any number of tmux instances may connect to the same session, and any number of {Window windows} may be present in the same session. Once all sessions are {Session#kill killed}, tmux exits.

Attributes

attached[R]

@return [Boolean]

attached?[R]

@return [Boolean]

buffers[R]

@tmux list-buffers @return [Array<Buffer>] All {Buffer buffers}

clients[R]

@return [Array<Client>] All {Client clients}

created_at[R]

@return [Time]

creation_time[R]

@return [Time]

current_pane[R]
current_window[R]
height[R]

@return [Integer]

identifier[R]

@return [String]

name[RW]

@overload name

@return [String]

@overload name=(new_name)

Renames the session.

@todo escape name
@return [String]
@tmux rename-session

@return [String]

num_windows[R]

@return [Integer]

options[R]

@return [OptionsList]

server[R]

@return [Server]

status_bar[R]

@return [StatusBar]

width[R]

@return [Integer]

windows[R]

@tmux list-windows @return [Hash{Number => Window}] All {Window windows} @tmuxver &gt;=1.1

Public Class Methods

new(server, name) click to toggle source
# File lib/tmux/session.rb, line 122
def initialize(server, name)
  @server, @name = server, name
  @status_bar = StatusBar.new(self)
  @options = OptionsList.new(:session, self, false)
end
options(session) click to toggle source

@return [Options]

# File lib/tmux/session.rb, line 15
def self.options(session)
  OptionsList.new(:session, session, true)
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/tmux/session.rb, line 100
def <=>(other)
  return nil unless other.is_a?(Session)
  [@server, @name] <=> [other.server, other.name]
end
==(other) click to toggle source

@return [Boolean]

# File lib/tmux/session.rb, line 86
def ==(other)
  self.class == other.class && @server == other.server && @name == other.name
end
any_client() click to toggle source

Returns a {Client client} that is displaying the session.

@return [Client, nil] A {Client client} that is displaying the session.

# File lib/tmux/session.rb, line 81
def any_client
  @server.clients({:session => self}).first
end
attach() click to toggle source

Attach to a session. Replaces the ruby process.

@return [void] @tmux attach

# File lib/tmux/session.rb, line 205
def attach
  exec "#{Tmux::BINARY} attach -t #{identifier}"
end
buffers_information(search = {}) click to toggle source

@param [Hash] search Filters the resulting hash using {FilterableHash#filter} @return [Hash] A hash with information for all buffers @tmux list-buffers

# File lib/tmux/session.rb, line 259
def buffers_information(search = {})
  hash = {}
  buffers = @server.invoke_command "list-buffers -t #{identifier}"
  buffers.each_line do |buffer|
    num, size = buffer.match(/^(\d+): (\d+) bytes/)[1..2]
    hash[num] = {:size => size}
  end
  hash.extend FilterableHash
  hash.filter(search)
end
create_window(args = {}) click to toggle source

Creates a new {Window window}.

@option args [Boolean] :after_number (false) If true, the new

{Window window} will be inserted at the next index up from the
specified number (or the {Client#current_window current}
{Window window}), moving {Window windows} up if necessary

@option args [Boolean] :kill_existing (false) Kill an existing

{Window window} if it conflicts with a desired number

@option args [Boolean] :make_active (true) Switch to the newly

generated {Window window}

@option args [String] :name Name of the new {Window window}

(optional)

@option args [Number] :number Number of the new {Window window}

(optional)

@option args [String] :command Command to run in the new {Window

window} (optional)

@tmux new-window @return [Window] The newly created {Window window}

# File lib/tmux/session.rb, line 38
def create_window(args = {})
  args = {
    :kill_existing => false,
    :make_active   => true,
    :after_number  => false,
  }.merge(args)

  flags = []
  # flags << "-d" unless args[:make_active]
  flags << "-a" if args[:after_number]
  flags << "-k" if args[:kill_existing]
  flags << "-n '#{args[:name]}'" if args[:name] # FIXME escaping
  flags << "-t #{args[:number]}" if args[:number]
  flags << args[:command] if args[:command]

  @server.invoke_command "new-window #{flags.join(" ")}"
  new_window = current_window
  unless args[:make_active]
    select_last_window
  end
  # return Window.new(self, num)
  return new_window
end
eql?(other) click to toggle source

@return [Boolean]

# File lib/tmux/session.rb, line 96
def eql?(other)
  self == other
end
hash() click to toggle source

@return [Number]

# File lib/tmux/session.rb, line 91
def hash
  [@server.hash, @number].hash
end
kill() click to toggle source

Kills the session.

@tmux kill-session @return [void]

# File lib/tmux/session.rb, line 213
def kill
  @server.invoke_command "kill-session -t #{identifier}"
end
lock() click to toggle source

Locks the session.

@tmux lock-session @return [void] @tmuxver &gt;=1.1

# File lib/tmux/session.rb, line 151
def lock
  @server.check_for_version!("1.1")

  @server.invoke_command "lock-session -t #{identifier}"
end
name=(new_name) click to toggle source
# File lib/tmux/session.rb, line 128
def name=(new_name)
  raise ArgumentError if new_name.to_s.strip.empty?
  ret = @server.invoke_command("rename-session -t #{identifier} '#{new_name}'")

  if ret.start_with?("duplicate session:")
    raise RuntimeError, ret
  end

  @name = new_name
end
select_last_window() click to toggle source

Select the last (previously selected) window.

@return [Window]

# File lib/tmux/session.rb, line 285
def select_last_window
  @server.invoke_command "last-window -t #{identifier}"
  current_window
end
select_next_window(num = 1) click to toggle source

Selects the next (higher index) window

@param [Number] num How many windows to move @tmuxver &gt;=1.3 @return [Window]

# File lib/tmux/session.rb, line 295
def select_next_window(num = 1)
  @server.invoke_command "select-window -t #{identifier}:+#{num}"
  current_window
end
select_previous_window(num = 1) click to toggle source

Selects the previous (lower index) window

@param [Number] num How many windows to move @tmuxver &gt;=1.3 @return [Window]

# File lib/tmux/session.rb, line 305
def select_previous_window(num = 1)
  @server.invoke_command "select-window -t:-#{num}"
  current_window
end
windows_information(search = {}) click to toggle source

@tmux list-windows @tmuxver &gt;=1.1 @param [Hash] search Filters the resulting hash using {FilterableHash#filter} @return [Hash] A hash with information for all windows @return [Hash]

# File lib/tmux/session.rb, line 222
def windows_information(search = {})
  @server.check_for_version!("1.1")

  hash = {}
  output = @server.invoke_command "list-windows -t #{identifier}"
  output.each_line do |session|
    params = session.match(/^(?<num>\d+): (?<name>.+?) \[(?<width>\d+)x(?<height>\d+)\]$/)
    next if params.nil? # >=1.3 displays layout information in indented lines
    num    = params[:num].to_i
    name   = params[:name]
    width  = params[:width].to_i
    height = params[:height].to_i

    hash[num] = {:num => num, :name => name, :width => width, :height => height}
  end
  hash.extend FilterableHash
  hash.filter(search)
end