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
@return [Boolean]
@return [Boolean]
@tmux list-buffers @return [Array<Buffer>] All {Buffer buffers}
@return [Array<Client>] All {Client clients}
@return [Time]
@return [Time]
@see Client#current_pane
@return (see Client#current_pane
)
@see Client#current_window
@return (see Client#current_window
)
@return [Integer]
@return [String]
@overload name
@return [String]
@overload name=(new_name)
Renames the session. @todo escape name @return [String] @tmux rename-session
@return [String]
@return [Integer]
@return [OptionsList]
@return [Server]
@return [StatusBar]
@return [Integer]
@tmux list-windows @return [Hash{Number => Window}] All {Window windows} @tmuxver >=1.1
Public Class Methods
# 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
@return [Options]
# File lib/tmux/session.rb, line 15 def self.options(session) OptionsList.new(:session, session, true) end
Public Instance Methods
# File lib/tmux/session.rb, line 100 def <=>(other) return nil unless other.is_a?(Session) [@server, @name] <=> [other.server, other.name] end
@return [Boolean]
# File lib/tmux/session.rb, line 86 def ==(other) self.class == other.class && @server == other.server && @name == other.name end
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 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
@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
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
@return [Boolean]
# File lib/tmux/session.rb, line 96 def eql?(other) self == other end
@return [Number]
# File lib/tmux/session.rb, line 91 def hash [@server.hash, @number].hash end
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
Locks the session.
@tmux lock-session @return [void] @tmuxver >=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
# 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 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
Selects the next (higher index) window
@param [Number] num How many windows to move @tmuxver >=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
Selects the previous (lower index) window
@param [Number] num How many windows to move @tmuxver >=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
@tmux list-windows @tmuxver >=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