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.new_session

Behavior: Creation.

Source and package
Qualified name
LibTmux::Server#new_session
Module
LibTmux
Declared in
Server
Package
libtmux
Source
gems/libtmux/lib/libtmux/server.rb
Other languages
PowerShell Julia Elixir PythonLuaTypeScriptRustGoJavaC#C++SwiftKotlinScala F#
def new_session: ( name: ::String, command: ::Array[::String], receipt: true, ?width: ::Integer?, ?height: ::Integer?, ?window_name: ::String?, ?cwd: ::String?, ?environment: ::Hash[::String, ::String], ?timeout: ::Numeric, ?cancel: untyped ) -> ::LibTmux::CreationReceiptdef new_session: ( name: ::String, command: ::Array[::String], ?receipt: false, ?width: ::Integer?, ?height: ::Integer?, ?window_name: ::String?, ?cwd: ::String?, ?environment: ::Hash[::String, ::String], ?timeout: ::Numeric, ?cancel: untyped ) -> ::LibTmux::Session

Description#

Behavior contract: Creation.

Examples#

Start a private server and create a session. Request a creation receipt to read the session, window, and pane IDs returned by that creation command. 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 new_session.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|
created = server.new_session(
name: "work", window_name: "main", command: ["/bin/cat"], receipt: true
)
puts "session: #{created.entity.id}"
puts "window: #{created.window.id}"
puts "pane: #{created.pane.id}"
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 new_session.rb

Expected output:

session: $0
window: @0
pane: %0
Parameters
  • name (::String) #

  • command (::Array[::String]) #

  • receipt (true) # for new_session(name, command, receipt, width, height, window_name, cwd, environment, timeout, cancel) [overload 1]

  • width (::Integer?) #

  • height (::Integer?) #

  • window_name (::String?) #

  • cwd (::String?) #

  • environment (::Hash[::String, ::String]) #

  • timeout (::Numeric) #

  • cancel (untyped) #

  • receipt (false) # for new_session(name, command, receipt, width, height, window_name, cwd, environment, timeout, cancel) [overload 2]

tmux command#

The tmux commands behind new_session.

tmux C API#

The C declarations in tmux that implement these commands.

Each path starts at a function a command runs, which is degree 1. The degree counts steps from there along the path, and each step is a call or a reference: degree 2 is reached from that function, degree 3 from the next, and so on.

Create a session and its first pane

  1. 1 cmd_new_session_exec
  2. calls → 2 spawn_window
  3. calls → 3 spawn_pane
  4. calls → 4 window_add_pane
  5. calls → 5 window_pane_create

In other ports#

Create a session

Esc

Type to search.

Reference previewOpen reference