Core Library0.xAPI Reference

Choose documentation 3

v0.1.1

Current version

v0.1.1
English

Early release libtmux is released, and its APIs may still change between releases. This site's structure and URLs may change too.

method libtmux-ruby v0.1.1

Server.list_sessions

Behavior: Live acquisition.

Source and package
Qualified name
LibTmux::Server#list_sessions
Module
LibTmux
Declared in
Server
Package
libtmux
Source
gems/libtmux/lib/libtmux/server.rb
Other languages
PowerShellcmdlet Juliafunction Elixirfunction PythonLuaTypeScriptRustGoJavaC#C++SwiftKotlinScalaF#function
def list_sessions: ( ?timeout: ::Numeric, ?cancel: untyped ) -> ::Array[::LibTmux::Session]

Description#

Behavior contract: Live acquisition.

Examples#

List live session handles from a server containing two sessions. Use Ruby 3.3 or newer with Bundler, and tmux 3.3a or newer, on Unix with /bin/cat and /bin/sh available. In an empty directory, save this Gemfile:

source "https://rubygems.org"
gem "libtmux", "0.1.1"

Save this complete program as list_sessions.rb. Its Server.start() block owns a private tmux server and stops it on exit, including after an error. View source

# frozen_string_literal: true
begin
# docs:begin main
require "libtmux"
LibTmux::Server.start do |server|
server.new_session(name: "work", command: ["/bin/cat"])
server.new_session(name: "logs", command: ["/bin/cat"])
sessions = server.list_sessions
puts "sessions: #{sessions.map(&:id).sort.join(', ')}"
end
# docs:end main
rescue StandardError => error
warn "#{error.class}: #{error.message}"
exit 1
end

Install the gem and run the program. An operation or cleanup error makes it exit unsuccessfully:

Terminal window
$ bundle install && \
bundle exec ruby list_sessions.rb

Expected output:

sessions: $0, $1
Parameters

tmux command#

The tmux commands behind list_sessions.

tmux C API#

The C declarations in tmux that implement these commands.

In other ports#

List the server’s sessions

Equivalents of List the server’s sessions in other languages
Language Equivalent
Python libtmux.Server.sessions
Lua libtmux.Snapshot.sessions
PowerShell LibTmux\Get-TmuxSession Acquires sessions through -Server, with optional exact -Id and -Name selectors.
Julia LibTmux.sessions sessions() reads membership from a captured Snapshot without contacting tmux.
Elixir LibTmux.Snapshot.sessions/1 Returns a Selection of captured sessions without contacting tmux.
TypeScript server.Server.sessions
Rust server.Server.sessions
Go tmux.Server.Sessions
Java io.github.libtmux.Server.sessions
Kotlin io.github.libtmux.kotlin.Server.sessions
Scala io.github.libtmux.scaladsl.Server.sessions
C# LibTmux.Server.Sessions
F# LibTmux.FSharp.Server.sessions Builds a deferred session query on LibTmux.Server. Query.list() acquires the results; it does not traverse the handle’s captured membership.
C++ libtmux::Server::sessions
Swift Server.sessions()
Esc

Type to search.

Reference previewOpen reference