ElixirHome

Choose documentation 1

pr-173

Current version

pr-173
English

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

MoreLess about this notice

libtmux for Elixir

Elixir-based tmux client

tmux client library for Elixir. Control tmux, navigate sessions, windows, and panes, watch for changes via control mode

Mix.install([{:libtmux, "0.1.1"}])
alias LibTmux.{Command, Pane, Ref, Selection, Server, Session, Snapshot, Window}
tmux = System.find_executable("tmux") || raise "tmux is not on PATH"
id = Base.encode16(:crypto.strong_rand_bytes(8), case: :lower)
dir = Path.join(System.tmp_dir!(), "libtmux-" <> id)
socket = Path.join(dir, "tmux.sock")
File.mkdir!(dir)
File.chmod!(dir, 0o700)
# libtmux works on a running server, so tmux itself starts the private one.
create = ["new-session", "-d", "-s", "demo"]
{_, 0} = System.cmd(tmux, ["-S", socket, "-f", "/dev/null" | create])
server = Server.new(executable: tmux, socket: socket)
# Lay out the session: name its window, split it, add a second window.
snapshot = Server.snapshot!(server)
session = snapshot |> Snapshot.sessions() |> Selection.one!()
editor = Session.active_window(snapshot, session)
{:ok, session_ref} = Ref.from_observation(session)
{:ok, editor_ref} = Ref.from_observation(editor)
Window.rename!(server, editor_ref, "editor")
left =
snapshot
|> Snapshot.panes()
|> Selection.one!(window_id: editor.id, active: true)
{:ok, left_ref} = Ref.from_observation(left)
%{id: right_id} = Pane.split!(server, left_ref, axis: :horizontal)
%{id: logs_id} = Session.new_window!(server, session_ref, "logs")
{:ok, right} = Ref.new(:pane, right_id, session.server_instance)
# Type a command into the new pane and wait for what it prints.
Pane.send_text!(server, right, "printf 'hello from %s\\n' tmux")
Pane.send_keys!(server, right, ["Enter"])
shown =
Enum.find_value(1..250, fn _ ->
screen = Pane.capture!(server, right)
screen =~ "hello from tmux" || (Process.sleep(20) && nil)
end)
shown || raise "the pane did not print hello from tmux"
# Move the focus an attached client sees: the pane, then the window.
select_pane = Command.new("select-pane", ["-t", right_id])
select_window = Command.new("select-window", ["-t", logs_id])
{:ok, _} = Server.run(server, select_pane)
{:ok, _} = Server.run(server, select_window)
# Walk the objects: down from the server, then up from one pane.
snapshot = Server.snapshot!(server)
sessions = Snapshot.sessions(snapshot)
for each <- sessions do
IO.puts("session #{each.name}")
links = Snapshot.related(snapshot, :session, each.id, :window_links)
for link <- Enum.sort_by(links, & &1.index) do
{:ok, window} = Snapshot.fetch(snapshot, :window, link.window_id)
panes = Window.panes(snapshot, window)
ids = Enum.map_join(panes, " ", & &1.id)
IO.puts(" window #{link.index}:#{window.name}: #{ids}")
end
end
pane = snapshot |> Snapshot.panes() |> Selection.one!(id: right_id)
window = Snapshot.related(snapshot, :pane, pane.id, :window)
[owner] = Snapshot.related(snapshot, :window, window.id, :sessions)
IO.puts("#{pane.id} is in window #{window.name} of session #{owner.name}")
Mix.install([{:libtmux, "0.1.1"}])
alias LibTmux.{Command, Pane, Ref, Selection, Server, Session, Snapshot, Window}
tmux = System.find_executable("tmux") || raise "tmux is not on PATH"
id = Base.encode16(:crypto.strong_rand_bytes(8), case: :lower)
dir = Path.join(System.tmp_dir!(), "libtmux-" <> id)
socket = Path.join(dir, "tmux.sock")
File.mkdir!(dir)
File.chmod!(dir, 0o700)
# libtmux works on a running server, so tmux itself starts the private one.
create = ["new-session", "-d", "-s", "demo"]
{_, 0} = System.cmd(tmux, ["-S", socket, "-f", "/dev/null" | create])
server = Server.new(executable: tmux, socket: socket)
# Lay out the session: name its window, split it, add a second window.
snapshot = Server.snapshot!(server)
session = snapshot |> Snapshot.sessions() |> Selection.one!()
editor = Session.active_window(snapshot, session)
{:ok, session_ref} = Ref.from_observation(session)
{:ok, editor_ref} = Ref.from_observation(editor)
Window.rename!(server, editor_ref, "editor")
left =
snapshot
|> Snapshot.panes()
|> Selection.one!(window_id: editor.id, active: true)
{:ok, left_ref} = Ref.from_observation(left)
%{id: right_id} = Pane.split!(server, left_ref, axis: :horizontal)
%{id: logs_id} = Session.new_window!(server, session_ref, "logs")
{:ok, right} = Ref.new(:pane, right_id, session.server_instance)
# Type a command into the new pane and wait for what it prints.
Pane.send_text!(server, right, "printf 'hello from %s\\n' tmux")
Pane.send_keys!(server, right, ["Enter"])
shown =
Enum.find_value(1..250, fn _ ->
screen = Pane.capture!(server, right)
screen =~ "hello from tmux" || (Process.sleep(20) && nil)
end)
shown || raise "the pane did not print hello from tmux"
# Move the focus an attached client sees: the pane, then the window.
select_pane = Command.new("select-pane", ["-t", right_id])
select_window = Command.new("select-window", ["-t", logs_id])
{:ok, _} = Server.run(server, select_pane)
{:ok, _} = Server.run(server, select_window)
# Walk the objects: down from the server, then up from one pane.
snapshot = Server.snapshot!(server)
sessions = Snapshot.sessions(snapshot)
for each <- sessions do
IO.puts("session #{each.name}")
links = Snapshot.related(snapshot, :session, each.id, :window_links)
for link <- Enum.sort_by(links, & &1.index) do
{:ok, window} = Snapshot.fetch(snapshot, :window, link.window_id)
panes = Window.panes(snapshot, window)
ids = Enum.map_join(panes, " ", & &1.id)
IO.puts(" window #{link.index}:#{window.name}: #{ids}")
end
end
pane = snapshot |> Snapshot.panes() |> Selection.one!(id: right_id)
window = Snapshot.related(snapshot, :pane, pane.id, :window)
[owner] = Snapshot.related(snapshot, :window, window.id, :sessions)
IO.puts("#{pane.id} is in window #{window.name} of session #{owner.name}")
Mix.install([{:libtmux, "0.1.1"}])
alias LibTmux.{Command, Pane, Ref, Selection, Server, Session, Snapshot, Window}
tmux = System.find_executable("tmux") || raise "tmux is not on PATH"
id = Base.encode16(:crypto.strong_rand_bytes(8), case: :lower)
dir = Path.join(System.tmp_dir!(), "libtmux-" <> id)
socket = Path.join(dir, "tmux.sock")
File.mkdir!(dir)
File.chmod!(dir, 0o700)
try do
# libtmux works on a running server, so tmux itself starts the private one.
create = ["new-session", "-d", "-s", "demo"]
{_, 0} = System.cmd(tmux, ["-S", socket, "-f", "/dev/null" | create])
server = Server.new(executable: tmux, socket: socket)
# Lay out the session: name its window, split it, add a second window.
snapshot = Server.snapshot!(server)
session = snapshot |> Snapshot.sessions() |> Selection.one!()
editor = Session.active_window(snapshot, session)
{:ok, session_ref} = Ref.from_observation(session)
{:ok, editor_ref} = Ref.from_observation(editor)
Window.rename!(server, editor_ref, "editor")
left =
snapshot
|> Snapshot.panes()
|> Selection.one!(window_id: editor.id, active: true)
{:ok, left_ref} = Ref.from_observation(left)
%{id: right_id} = Pane.split!(server, left_ref, axis: :horizontal)
%{id: logs_id} = Session.new_window!(server, session_ref, "logs")
{:ok, right} = Ref.new(:pane, right_id, session.server_instance)
# Type a command into the new pane and wait for what it prints.
Pane.send_text!(server, right, "printf 'hello from %s\\n' tmux")
Pane.send_keys!(server, right, ["Enter"])
shown =
Enum.find_value(1..250, fn _ ->
screen = Pane.capture!(server, right)
screen =~ "hello from tmux" || (Process.sleep(20) && nil)
end)
shown || raise "the pane did not print hello from tmux"
# Move the focus an attached client sees: the pane, then the window.
select_pane = Command.new("select-pane", ["-t", right_id])
select_window = Command.new("select-window", ["-t", logs_id])
{:ok, _} = Server.run(server, select_pane)
{:ok, _} = Server.run(server, select_window)
# Walk the objects: down from the server, then up from one pane.
snapshot = Server.snapshot!(server)
sessions = Snapshot.sessions(snapshot)
for each <- sessions do
IO.puts("session #{each.name}")
links = Snapshot.related(snapshot, :session, each.id, :window_links)
for link <- Enum.sort_by(links, & &1.index) do
{:ok, window} = Snapshot.fetch(snapshot, :window, link.window_id)
panes = Window.panes(snapshot, window)
ids = Enum.map_join(panes, " ", & &1.id)
IO.puts(" window #{link.index}:#{window.name}: #{ids}")
end
end
pane = snapshot |> Snapshot.panes() |> Selection.one!(id: right_id)
window = Snapshot.related(snapshot, :pane, pane.id, :window)
[owner] = Snapshot.related(snapshot, :window, window.id, :sessions)
IO.puts("#{pane.id} is in window #{window.name} of session #{owner.name}")
after
System.cmd(tmux, ["-S", socket, "kill-server"], stderr_to_stdout: true)
File.rm_rf(dir)
end
Mix.install([{:libtmux, "0.1.1"}])
alias LibTmux.{Command, Pane, Ref, Selection, Server, Session, Snapshot, Window}
tmux = System.find_executable("tmux") || raise "tmux is not on PATH"
id = Base.encode16(:crypto.strong_rand_bytes(8), case: :lower)
dir = Path.join(System.tmp_dir!(), "libtmux-" <> id)
socket = Path.join(dir, "tmux.sock")
File.mkdir!(dir)
File.chmod!(dir, 0o700)
try do
# libtmux works on a running server, so tmux itself starts the private one.
create = ["new-session", "-d", "-s", "demo"]
{_, 0} = System.cmd(tmux, ["-S", socket, "-f", "/dev/null" | create])
server = Server.new(executable: tmux, socket: socket)
# Lay out the session: name its window, split it, add a second window.
snapshot = Server.snapshot!(server)
session = snapshot |> Snapshot.sessions() |> Selection.one!()
editor = Session.active_window(snapshot, session)
{:ok, session_ref} = Ref.from_observation(session)
{:ok, editor_ref} = Ref.from_observation(editor)
Window.rename!(server, editor_ref, "editor")
left =
snapshot
|> Snapshot.panes()
|> Selection.one!(window_id: editor.id, active: true)
{:ok, left_ref} = Ref.from_observation(left)
%{id: right_id} = Pane.split!(server, left_ref, axis: :horizontal)
%{id: logs_id} = Session.new_window!(server, session_ref, "logs")
{:ok, right} = Ref.new(:pane, right_id, session.server_instance)
# Type a command into the new pane and wait for what it prints.
Pane.send_text!(server, right, "printf 'hello from %s\\n' tmux")
Pane.send_keys!(server, right, ["Enter"])
shown =
Enum.find_value(1..250, fn _ ->
screen = Pane.capture!(server, right)
screen =~ "hello from tmux" || (Process.sleep(20) && nil)
end)
shown || raise "the pane did not print hello from tmux"
# Move the focus an attached client sees: the pane, then the window.
select_pane = Command.new("select-pane", ["-t", right_id])
select_window = Command.new("select-window", ["-t", logs_id])
{:ok, _} = Server.run(server, select_pane)
{:ok, _} = Server.run(server, select_window)
# Walk the objects: down from the server, then up from one pane.
snapshot = Server.snapshot!(server)
sessions = Snapshot.sessions(snapshot)
for each <- sessions do
IO.puts("session #{each.name}")
links = Snapshot.related(snapshot, :session, each.id, :window_links)
for link <- Enum.sort_by(links, & &1.index) do
{:ok, window} = Snapshot.fetch(snapshot, :window, link.window_id)
panes = Window.panes(snapshot, window)
ids = Enum.map_join(panes, " ", & &1.id)
IO.puts(" window #{link.index}:#{window.name}: #{ids}")
end
end
pane = snapshot |> Snapshot.panes() |> Selection.one!(id: right_id)
window = Snapshot.related(snapshot, :pane, pane.id, :window)
[owner] = Snapshot.related(snapshot, :window, window.id, :sessions)
IO.puts("#{pane.id} is in window #{window.name} of session #{owner.name}")
after
System.cmd(tmux, ["-S", socket, "kill-server"], stderr_to_stdout: true)
File.rm_rf(dir)
end
Example details
No tmux server yet

tmux before the first call: no server is running.

%0 sh
[demo]

tmux after System.cmd: added session demo.

%0 sh
[demo]

tmux after Server.new: unchanged, the call sent no command.

%0 sh
[demo]

tmux after Server.snapshot!: unchanged.

%0 sh
[demo]

tmux after Selection.one!: unchanged, the call sent no command.

%0 sh
[demo]

tmux after Session.active_window: unchanged, the call sent no command.

%0 sh
[demo]

tmux after Ref.from_observation: unchanged, the call sent no command.

%0 sh
[demo]

tmux after Ref.from_observation: unchanged, the call sent no command.

%0 sh
[demo]

tmux after Window.rename!: renamed window 0:sh to 0:editor.

%0 sh
[demo]

tmux after Selection.one!: unchanged, the call sent no command.

%0 sh
[demo]

tmux after Ref.from_observation: unchanged, the call sent no command.

%0 sh
%1 sh
[demo]

tmux after Pane.split!: added pane %1 to window 0:editor.

%0 sh
%1 sh
[demo]

tmux after Session.new_window!: added window 1:logs.

%0 sh
%1 sh
[demo]

tmux after Ref.new: unchanged, the call sent no command.

%0 sh
%1 sh
[demo]

tmux after Pane.send_text!: sent keys to pane %1.

%0 sh
%1 sh
[demo]

tmux after Pane.send_keys!: sent keys to pane %1.

%0 sh
%1 sh
$ printf 'hello from %s\n' tmux
hello from tmux
$
[demo]

tmux after Pane.capture!: read pane %1.

%0 sh
%1 sh
$ printf 'hello from %s\n' tmux
hello from tmux
$
[demo]

tmux after Command.new: unchanged, the call sent no command.

%0 sh
%1 sh
$ printf 'hello from %s\n' tmux
hello from tmux
$
[demo]

tmux after Command.new: unchanged, the call sent no command.

%0 sh
%1 sh
$ printf 'hello from %s\n' tmux
hello from tmux
$
[demo]

tmux after Server.run: selected pane %1 in window 0:editor.

%2 sh
[demo]

tmux after Server.run: selected window 1:logs.

%2 sh
[demo]

tmux after Server.snapshot!: unchanged.

%2 sh
[demo]

tmux after Snapshot.sessions: unchanged, the call sent no command.

%2 sh
[demo]

tmux after Snapshot.related: unchanged, the call sent no command.

%2 sh
[demo]

tmux after Window.panes: unchanged, the call sent no command.

%2 sh
[demo]

tmux after Window.panes: unchanged, the call sent no command.

%2 sh
[demo]

tmux after Selection.one!: unchanged, the call sent no command.

%2 sh
[demo]

tmux after Snapshot.related: unchanged, the call sent no command.

%2 sh
[demo]

tmux after Snapshot.related: unchanged, the call sent no command.

No sessions

tmux after System.cmd: the server has exited.

  1. Before the first call

    No tmux server is running yet.

  2. System.cmd returned exit status

    {
    "status": 0
    }
    1 tmux command, 1 that changes tmux
    1. new-session -d -s demo no output
  3. Server.new returned Server

    {
    "socket": "/tmp/tmp/libtmux-0123456789abcdef/tmux.sock",
    "executable": "/usr/bin/tmux"
    }

    The call sent no tmux command.

  4. Server.snapshot! returned Snapshot

    {
    "windows": 1,
    "sessions": 1,
    "panes": 1
    }
    11 tmux commands
    1. list-sessions -F '#{session_id} #{session_attached}' $0 0
    2. list-windows -a -F '#{session_id} #{window_index} #{window_id} #{window_active} #{window_width} #{window_height} #{window_zoomed_flag}' $0 0 @0 1 80 24 0
    3. list-panes -a -F '#{pane_id} #{window_id} #{pane_index} #{pane_active} #{pane_dead} #{pane_width} #{pane_height} #{pane_pid} #{pane_dead_status}' %0 @0 0 1 0 80 24 3471676
    4. list-clients -F 'v1:#{s|\\|\\134|;s|\$|\\044|;s||\\001|;s||\\002|;s||\\003|;s||\\004|;s||\\005|;s||\\006|;s||\\007|;s||\\010|;s| |\\011|;s| |\\012|;s| |\\013|;s| |\\014|;s| |\\015|;s||\\016|;s||\\017|;s||\\020|;s||\\021|;s||\\022|;s||\\023|;s||\\024|;s||\\025|;s||\\026|;s||\\027|;s||\\030|;s||\\031|;s||\\032|;s||\\033|;s||\\034|;s||\\035|;s||\\036|;s||\\037|;s||\\177|:cl… no output
    5. list-sessions -F 'r1:2 v1:#{s|\\|\\134|;s|\$|\\044|;s||\\001|;s||\\002|;s||\\003|;s||\\004|;s||\\005|;s||\\006|;s||\\007|;s||\\010|;s| |\\011|;s| |\\012|;s| |\\013|;s| |\\014|;s| |\\015|;s||\\016|;s||\\017|;s||\\020|;s||\\021|;s||\\022|;s||\\023|;s||\\024|;s||\\025|;s||\\026|;s||\\027|;s||\\030|;s||\\031|;s||\\032|;s||\\033|;s||\\034|;s||\\035|;s||\\036|;s||\\037|;s||\\1… r1:2 v1:\0440 v1:demo
    6. list-panes -a -F 'r1:4 v1:#{s|\\|\\134|;s|\$|\\044|;s||\\001|;s||\\002|;s||\\003|;s||\\004|;s||\\005|;s||\\006|;s||\\007|;s||\\010|;s| |\\011|;s| |\\012|;s| |\\013|;s| |\\014|;s| |\\015|;s||\\016|;s||\\017|;s||\\020|;s||\\021|;s||\\022|;s||\\023|;s||\\024|;s||\\025|;s||\\026|;s||\\027|;s||\\030|;s||\\031|;s||\\032|;s||\\033|;s||\\034|;s||\\035|;s||\\036|;s||\\037|;s||\\1… r1:4 v1:%0 v1:sh v1:/tmp/marked v1:host
    7. list-windows -a -F 'r1:3 v1:#{s|\\|\\134|;s|\$|\\044|;s||\\001|;s||\\002|;s||\\003|;s||\\004|;s||\\005|;s||\\006|;s||\\007|;s||\\010|;s| |\\011|;s| |\\012|;s| |\\013|;s| |\\014|;s| |\\015|;s||\\016|;s||\\017|;s||\\020|;s||\\021|;s||\\022|;s||\\023|;s||\\024|;s||\\025|;s||\\026|;s||\\027|;s||\\030|;s||\\031|;s||\\032|;s||\\033|;s||\\034|;s||\\035|;s||\\036|;s||\\037|;s||\… r1:3 v1:@0 v1:sh v1:{"V":2,"L":{"t":"p","w":80,"h":24,"x":0,"y":0,"a":true,"i":0,"I":"%0"}}
    8. list-sessions -F '#{session_id} #{session_attached}' $0 0
    9. list-windows -a -F '#{session_id} #{window_index} #{window_id} #{window_active} #{window_width} #{window_height} #{window_zoomed_flag}' $0 0 @0 1 80 24 0
    10. list-panes -a -F '#{pane_id} #{window_id} #{pane_index} #{pane_active} #{pane_dead} #{pane_width} #{pane_height} #{pane_pid} #{pane_dead_status}' %0 @0 0 1 0 80 24 3471676
    11. list-clients -F 'v1:#{s|\\|\\134|;s|\$|\\044|;s||\\001|;s||\\002|;s||\\003|;s||\\004|;s||\\005|;s||\\006|;s||\\007|;s||\\010|;s| |\\011|;s| |\\012|;s| |\\013|;s| |\\014|;s| |\\015|;s||\\016|;s||\\017|;s||\\020|;s||\\021|;s||\\022|;s||\\023|;s||\\024|;s||\\025|;s||\\026|;s||\\027|;s||\\030|;s||\\031|;s||\\032|;s||\\033|;s||\\034|;s||\\035|;s||\\036|;s||\\037|;s||\\177|:cl… no output

    Before these, the library asked tmux about itself 2 times (its version, its daemon, how a control client reads escapes).

  5. Selection.one! returned Session

    {
    "id": "$0",
    "name": "demo"
    }

    The call sent no tmux command.

  6. Session.active_window returned Window

    {
    "id": "@0",
    "name": "sh"
    }

    The call sent no tmux command.

  7. Ref.from_observation returned Ref

    {
    "id": "$0",
    "entity": "session"
    }

    The call sent no tmux command.

  8. Ref.from_observation returned Ref

    {
    "id": "@0",
    "entity": "window"
    }

    The call sent no tmux command.

  9. Window.rename! returned :ok

    "ok"
    1 tmux command, 1 that changes tmux
    1. rename-window -t @0 -- editor no output

    Before these, the library asked tmux about itself 1 time (its version, its daemon, how a control client reads escapes).

  10. Selection.one! returned Pane

    {
    "id": "%0"
    }

    The call sent no tmux command.

  11. Ref.from_observation returned Ref

    {
    "id": "%0",
    "entity": "pane"
    }

    The call sent no tmux command.

  12. Pane.split! returned map

    {
    "id": "%1"
    }
    1 tmux command, 1 that changes tmux
    1. split-window -t %0 -P -F #{pane_id} -h -d -- %1

    Before these, the library asked tmux about itself 1 time (its version, its daemon, how a control client reads escapes).

  13. Session.new_window! returned map

    {
    "id": "@1"
    }
    1 tmux command, 1 that changes tmux
    1. new-window -d -P -F #{window_id} -t $0: -n logs -- @1

    Before these, the library asked tmux about itself 1 time (its version, its daemon, how a control client reads escapes).

  14. Ref.new returned Ref

    {
    "id": "%1",
    "entity": "pane"
    }

    The call sent no tmux command.

  15. Pane.send_text! returned :ok

    "ok"
    1 tmux command, 1 that changes tmux
    1. send-keys -H -t %1 -- 70 72 69 6E 74 66 20 27 68 65 6C 6C 6F 20 66 72 6F 6D 20 25 73 5C 6E 27 20 74 6D 75 78 no output

    Before these, the library asked tmux about itself 1 time (its version, its daemon, how a control client reads escapes).

  16. Pane.send_keys! returned :ok

    "ok"
    1 tmux command, 1 that changes tmux
    1. send-keys -t %1 -- Enter no output

    Before these, the library asked tmux about itself 1 time (its version, its daemon, how a control client reads escapes).

  17. Pane.capture! returned binary

    "$ printf 'hello from %s\\n' tmux\nhello from tmux\n$\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
    1 tmux command
    1. capture-pane -p -t %1 -S 0 -E - $ printf 'hello from %s\n' tmux hello from tmux $

    Before these, the library asked tmux about itself 1 time (its version, its daemon, how a control client reads escapes).

  18. Command.new returned Command

    {
    "args": [
    "-t",
    "%1"
    ],
    "name": "select-pane"
    }

    The call sent no tmux command.

  19. Command.new returned Command

    {
    "args": [
    "-t",
    "@1"
    ],
    "name": "select-window"
    }

    The call sent no tmux command.

  20. Server.run returned Result

    {
    "exit_status": 0,
    "stdout": "",
    "stderr": ""
    }
    1 tmux command, 1 that changes tmux
    1. select-pane -t %1 no output
  21. Server.run returned Result

    {
    "exit_status": 0,
    "stdout": "",
    "stderr": ""
    }
    1 tmux command, 1 that changes tmux
    1. select-window -t @1 no output
  22. Server.snapshot! returned Snapshot

    {
    "windows": 2,
    "sessions": 1,
    "panes": 3
    }
    11 tmux commands
    1. list-sessions -F '#{session_id} #{session_attached}' $0 0
    2. list-windows -a -F '#{session_id} #{window_index} #{window_id} #{window_active} #{window_width} #{window_height} #{window_zoomed_flag}' $0 0 @0 0 80 24 0 $0 1 @1 1 80 24 0
    3. list-panes -a -F '#{pane_id} #{window_id} #{pane_index} #{pane_active} #{pane_dead} #{pane_width} #{pane_height} #{pane_pid} #{pane_dead_status}' %0 @0 0 0 0 40 24 3471676 %1 @0 1 1 0 39 24 3472292 %2 @1 0 1 0 80 24 3472410
    4. list-clients -F 'v1:#{s|\\|\\134|;s|\$|\\044|;s||\\001|;s||\\002|;s||\\003|;s||\\004|;s||\\005|;s||\\006|;s||\\007|;s||\\010|;s| |\\011|;s| |\\012|;s| |\\013|;s| |\\014|;s| |\\015|;s||\\016|;s||\\017|;s||\\020|;s||\\021|;s||\\022|;s||\\023|;s||\\024|;s||\\025|;s||\\026|;s||\\027|;s||\\030|;s||\\031|;s||\\032|;s||\\033|;s||\\034|;s||\\035|;s||\\036|;s||\\037|;s||\\177|:cl… no output
    5. list-sessions -F 'r1:2 v1:#{s|\\|\\134|;s|\$|\\044|;s||\\001|;s||\\002|;s||\\003|;s||\\004|;s||\\005|;s||\\006|;s||\\007|;s||\\010|;s| |\\011|;s| |\\012|;s| |\\013|;s| |\\014|;s| |\\015|;s||\\016|;s||\\017|;s||\\020|;s||\\021|;s||\\022|;s||\\023|;s||\\024|;s||\\025|;s||\\026|;s||\\027|;s||\\030|;s||\\031|;s||\\032|;s||\\033|;s||\\034|;s||\\035|;s||\\036|;s||\\037|;s||\\1… r1:2 v1:\0440 v1:demo
    6. list-panes -a -F 'r1:4 v1:#{s|\\|\\134|;s|\$|\\044|;s||\\001|;s||\\002|;s||\\003|;s||\\004|;s||\\005|;s||\\006|;s||\\007|;s||\\010|;s| |\\011|;s| |\\012|;s| |\\013|;s| |\\014|;s| |\\015|;s||\\016|;s||\\017|;s||\\020|;s||\\021|;s||\\022|;s||\\023|;s||\\024|;s||\\025|;s||\\026|;s||\\027|;s||\\030|;s||\\031|;s||\\032|;s||\\033|;s||\\034|;s||\\035|;s||\\036|;s||\\037|;s||\\1… r1:4 v1:%0 v1:sh v1:/tmp/marked v1:host r1:4 v1:%1 v1:sh v1:/tmp/marked v1:host r1:4 v1:%2 v1:sh v1:/tmp/marked v1:host
    7. list-windows -a -F 'r1:3 v1:#{s|\\|\\134|;s|\$|\\044|;s||\\001|;s||\\002|;s||\\003|;s||\\004|;s||\\005|;s||\\006|;s||\\007|;s||\\010|;s| |\\011|;s| |\\012|;s| |\\013|;s| |\\014|;s| |\\015|;s||\\016|;s||\\017|;s||\\020|;s||\\021|;s||\\022|;s||\\023|;s||\\024|;s||\\025|;s||\\026|;s||\\027|;s||\\030|;s||\\031|;s||\\032|;s||\\033|;s||\\034|;s||\\035|;s||\\036|;s||\\037|;s||\… r1:3 v1:@0 v1:editor v1:{"V":2,"L":{"t":"h","w":80,"h":24,"x":0,"y":0,"c":[{"t":"p","w":40,"h":24,"x":0,"y":0,"l":0,"i":0,"I":"%0"},{"t":"p","w":39,"h":24,"x":41,"y":0,"a":true,"i":1,"I":"%1"}]}} r1:3 v1:@1 v1:logs v1:{"V":2,"L":{"t":"p","w":80,"h":24,"x":0,"y":0,"a":true,"i":0,"I":"%2"}}
    8. list-sessions -F '#{session_id} #{session_attached}' $0 0
    9. list-windows -a -F '#{session_id} #{window_index} #{window_id} #{window_active} #{window_width} #{window_height} #{window_zoomed_flag}' $0 0 @0 0 80 24 0 $0 1 @1 1 80 24 0
    10. list-panes -a -F '#{pane_id} #{window_id} #{pane_index} #{pane_active} #{pane_dead} #{pane_width} #{pane_height} #{pane_pid} #{pane_dead_status}' %0 @0 0 0 0 40 24 3471676 %1 @0 1 1 0 39 24 3472292 %2 @1 0 1 0 80 24 3472410
    11. list-clients -F 'v1:#{s|\\|\\134|;s|\$|\\044|;s||\\001|;s||\\002|;s||\\003|;s||\\004|;s||\\005|;s||\\006|;s||\\007|;s||\\010|;s| |\\011|;s| |\\012|;s| |\\013|;s| |\\014|;s| |\\015|;s||\\016|;s||\\017|;s||\\020|;s||\\021|;s||\\022|;s||\\023|;s||\\024|;s||\\025|;s||\\026|;s||\\027|;s||\\030|;s||\\031|;s||\\032|;s||\\033|;s||\\034|;s||\\035|;s||\\036|;s||\\037|;s||\\177|:cl… no output

    Before these, the library asked tmux about itself 2 times (its version, its daemon, how a control client reads escapes).

  23. Snapshot.sessions returned Selection

    [
    {
    "id": "$0",
    "name": "demo"
    }
    ]

    The call sent no tmux command.

  24. Snapshot.related returned [WindowLink]

    [
    {
    "index": 0,
    "window": "@0"
    },
    {
    "index": 1,
    "window": "@1"
    }
    ]

    The call sent no tmux command.

  25. Window.panes returned Selection

    [
    "%0",
    "%1"
    ]

    The call sent no tmux command.

  26. Window.panes returned Selection

    [
    "%2"
    ]

    The call sent no tmux command.

  27. Selection.one! returned Pane

    {
    "id": "%1"
    }

    The call sent no tmux command.

  28. Snapshot.related returned Window

    {
    "id": "@0",
    "name": "editor"
    }

    The call sent no tmux command.

  29. Snapshot.related returned [Session]

    {
    "id": "$0",
    "name": "demo"
    }

    The call sent no tmux command.

  30. System.cmd returned exit status

    {
    "status": 0
    }
    1 tmux command, 1 that changes tmux
    1. kill-server no output
1/28
Run this example

POSIX shell, tmux 3.3 or newer, Elixir 1.20.4 or newer, Erlang/OTP 29.1.2 or a newer 29.x release, access to hex.pm, and a C11 compiler on Linux.

Save the program above as quickstart.exs in a new directory, along with the files below.

Cleanup is omitted; the private tmux server and its temporary files may remain. Select Cleanup to remove them when the program finishes. The program stops its private tmux server and removes any temporary files it created when it finishes. An unmatched result or a raised error ends the script with its message and stack trace, so there is no separate error handling to add. Every version checks required results.

Setup and run

unset TMUX TMUX_PANE
export ENV=/dev/null BASH_ENV=/dev/null SHELL=/bin/sh
elixir quickstart.exs

Expected output

session demo
window 0:editor: %0 %1
window 1:logs: %2
%1 is in window editor of session demo

Install libtmux

mix.exsFrom Git
mix.exs
mix.exs
libtmux 0.1.1 0.x Hex
{:libtmux, "~> 0.1.1"}
Then
$ mix deps.get
{:libtmux, github: "libtmux/libtmux-elixir", tag: "v0.1.1"}

Add the tuple to the deps list in mix.exs, then fetch it. Needs Elixir 1.20.4 or newer, Erlang/OTP 29.1.2 or a newer 29.x release, tmux 3.3 or newer (the planned floor), and a C11 compiler on Linux.

Pins the tagged source; the registry release is the default.

API references

Esc
Search in

Type to search.

Reference previewOpen reference