Server.list_sessions
Behavior: Live acquisition.
Source and package
-
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/catand/bin/shavailable. In an empty directory, save thisGemfile:source "https://rubygems.org"gem "libtmux", "0.1.1"Save this complete program as
list_sessions.rb. ItsServer.start()block owns a private tmux server and stops it on exit, including after an error. View source# frozen_string_literal: truebegin# docs:begin mainrequire "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_sessionsputs "sessions: #{sessions.map(&:id).sort.join(', ')}"end# docs:end mainrescue StandardError => errorwarn "#{error.class}: #{error.message}"exit 1endInstall the gem and run the program. An operation or cleanup error makes it exit unsuccessfully:
Terminal window $ bundle install && \bundle exec ruby list_sessions.rbExpected output:
sessions: $0, $1
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
| Language | Equivalent |
|---|---|
| Python | libtmux |
| Lua | libtmux |
| PowerShell | Lib Acquires sessions through -Server, with optional exact -Id and -Name selectors. |
| Julia | Lib sessions() reads membership from a captured Snapshot without contacting tmux. |
| Elixir | Lib Returns a Selection of captured sessions without contacting tmux. |
| TypeScript | server |
| Rust | server |
| Go | tmux |
| Java | io |
| Kotlin | io |
| Scala | io |
| C# | Lib |
| F# | Lib Builds a deferred session query on LibTmux.Server. Query.list() acquires the results; it does not traverse the handle’s captured membership. |
| C++ | libtmux:: |
| Swift | Server |