F#Home

Choose documentation 1

latest

Current version

latest
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 F#

F#-based tmux client

tmux client library for F#. Control tmux, navigate sessions, windows, and panes, send keys, watch for changes via control mode, capture pane contents

Built on the C# library for .NET. The packages share their source repository and releases.

open System
open System.Threading
open LibTmux
open LibTmux.FSharp
let runAsync () =
task {
use deadline = new CancellationTokenSource(TimeSpan.FromSeconds 30.)
let token = deadline.Token
let options =
ServerConnectionOptions(
SocketName = "fsharp-" + Guid.NewGuid().ToString("N"),
ConfigurationFile = "/dev/null",
TmuxBinaryPath =
(Environment.GetEnvironmentVariable "LIBTMUX_TMUX"
|> Option.ofObj
|> Option.defaultValue "tmux")
)
let! owned = LibTmux.Server.CreateOwnedAsync(options, token)
let! session =
owned.Value.CreateSessionAsync(
NewSessionRequest(Name = "demo", Command = "/bin/sh"),
token
)
// The new session's active window is its first; name it.
let! active =
session
|> Session.windows
|> Query.where (WindowFields.active |> Filter.eq true)
|> Query.list token
let! editor = active[0] |> Window.rename token "editor"
// Split its active pane; the new pane is on the right and stays
// in the background, so the left pane is still active.
let! left = editor |> Window.activePane token
let! right =
left
|> Pane.split
token
(SplitPaneRequest(Direction = PaneDirection.Right))
// A second window, also left in the background.
let! logs =
session |> Session.newWindow token (NewWindowRequest(Name = "logs"))
// Type a command and wait for what it prints, not for its echo.
let! waited =
right
|> Pane.sendAndWait
token
(TimeSpan.FromSeconds 10.)
"printf 'hello from %s\\n' tmux"
"hello from tmux"
// Select the right pane, then the logs window.
let! selected = right |> Pane.select token
let! current = logs |> Window.select token
// Walk a snapshot down from the server: sessions, windows, panes.
let! server = LibTmux.Server.ConnectAsync(options, token)
let! snapshot = server |> Server.capture token SnapshotDepth.Panes
let sessions = snapshot.Sessions
for session in sessions do
printfn "session %s" session.Name
let windows = session.Windows
for window in windows do
let panes = window.Panes
let ids = [ for pane in panes -> string pane.Id ]
printfn
" window %d:%s: %s"
window.Index
window.Name
(String.Join(" ", ids))
// Then up from one pane to its window and session.
let pane = snapshot.Panes |> Seq.find (fun pane -> pane.Id = right.Id)
let window = pane.Window
let owner = window.Session
printfn
"%O is in window %s of session %s"
pane.Id
window.Name
owner.Name
}
runAsync().GetAwaiter().GetResult()
open System
open System.Threading
open LibTmux
open LibTmux.FSharp
let runAsync () =
task {
use deadline = new CancellationTokenSource(TimeSpan.FromSeconds 30.)
let token = deadline.Token
let options =
ServerConnectionOptions(
SocketName = "fsharp-" + Guid.NewGuid().ToString("N"),
ConfigurationFile = "/dev/null",
TmuxBinaryPath =
(Environment.GetEnvironmentVariable "LIBTMUX_TMUX"
|> Option.ofObj
|> Option.defaultValue "tmux")
)
let! owned = LibTmux.Server.CreateOwnedAsync(options, token)
let! session =
owned.Value.CreateSessionAsync(
NewSessionRequest(Name = "demo", Command = "/bin/sh"),
token
)
// The new session's active window is its first; name it.
let! active =
session
|> Session.windows
|> Query.where (WindowFields.active |> Filter.eq true)
|> Query.list token
let! editor = active[0] |> Window.rename token "editor"
// Split its active pane; the new pane is on the right and stays
// in the background, so the left pane is still active.
let! left = editor |> Window.activePane token
let! right =
left
|> Pane.split
token
(SplitPaneRequest(Direction = PaneDirection.Right))
// A second window, also left in the background.
let! logs =
session |> Session.newWindow token (NewWindowRequest(Name = "logs"))
// Type a command and wait for what it prints, not for its echo.
let! waited =
right
|> Pane.sendAndWait
token
(TimeSpan.FromSeconds 10.)
"printf 'hello from %s\\n' tmux"
"hello from tmux"
// Select the right pane, then the logs window.
let! selected = right |> Pane.select token
let! current = logs |> Window.select token
// Walk a snapshot down from the server: sessions, windows, panes.
let! server = LibTmux.Server.ConnectAsync(options, token)
let! snapshot = server |> Server.capture token SnapshotDepth.Panes
let sessions = snapshot.Sessions
for session in sessions do
printfn "session %s" session.Name
let windows = session.Windows
for window in windows do
let panes = window.Panes
let ids = [ for pane in panes -> string pane.Id ]
printfn
" window %d:%s: %s"
window.Index
window.Name
(String.Join(" ", ids))
// Then up from one pane to its window and session.
let pane = snapshot.Panes |> Seq.find (fun pane -> pane.Id = right.Id)
let window = pane.Window
let owner = window.Session
printfn
"%O is in window %s of session %s"
pane.Id
window.Name
owner.Name
}
try
runAsync().GetAwaiter().GetResult()
with error ->
raise (InvalidOperationException(
"tmux quickstart failed", error))
open System
open System.Threading
open LibTmux
open LibTmux.FSharp
let runAsync () =
task {
use deadline = new CancellationTokenSource(TimeSpan.FromSeconds 30.)
let token = deadline.Token
let options =
ServerConnectionOptions(
SocketName = "fsharp-" + Guid.NewGuid().ToString("N"),
ConfigurationFile = "/dev/null",
TmuxBinaryPath =
(Environment.GetEnvironmentVariable "LIBTMUX_TMUX"
|> Option.ofObj
|> Option.defaultValue "tmux")
)
use! owned = LibTmux.Server.CreateOwnedAsync(options, token)
let! session =
owned.Value.CreateSessionAsync(
NewSessionRequest(Name = "demo", Command = "/bin/sh"),
token
)
// The new session's active window is its first; name it.
let! active =
session
|> Session.windows
|> Query.where (WindowFields.active |> Filter.eq true)
|> Query.list token
let! editor = active[0] |> Window.rename token "editor"
// Split its active pane; the new pane is on the right and stays
// in the background, so the left pane is still active.
let! left = editor |> Window.activePane token
let! right =
left
|> Pane.split
token
(SplitPaneRequest(Direction = PaneDirection.Right))
// A second window, also left in the background.
let! logs =
session |> Session.newWindow token (NewWindowRequest(Name = "logs"))
// Type a command and wait for what it prints, not for its echo.
let! waited =
right
|> Pane.sendAndWait
token
(TimeSpan.FromSeconds 10.)
"printf 'hello from %s\\n' tmux"
"hello from tmux"
// Select the right pane, then the logs window.
let! selected = right |> Pane.select token
let! current = logs |> Window.select token
// Walk a snapshot down from the server: sessions, windows, panes.
let! server = LibTmux.Server.ConnectAsync(options, token)
let! snapshot = server |> Server.capture token SnapshotDepth.Panes
let sessions = snapshot.Sessions
for session in sessions do
printfn "session %s" session.Name
let windows = session.Windows
for window in windows do
let panes = window.Panes
let ids = [ for pane in panes -> string pane.Id ]
printfn
" window %d:%s: %s"
window.Index
window.Name
(String.Join(" ", ids))
// Then up from one pane to its window and session.
let pane = snapshot.Panes |> Seq.find (fun pane -> pane.Id = right.Id)
let window = pane.Window
let owner = window.Session
printfn
"%O is in window %s of session %s"
pane.Id
window.Name
owner.Name
}
runAsync().GetAwaiter().GetResult()
open System
open System.Threading
open LibTmux
open LibTmux.FSharp
let runAsync () =
task {
use deadline = new CancellationTokenSource(TimeSpan.FromSeconds 30.)
let token = deadline.Token
let options =
ServerConnectionOptions(
SocketName = "fsharp-" + Guid.NewGuid().ToString("N"),
ConfigurationFile = "/dev/null",
TmuxBinaryPath =
(Environment.GetEnvironmentVariable "LIBTMUX_TMUX"
|> Option.ofObj
|> Option.defaultValue "tmux")
)
use! owned = LibTmux.Server.CreateOwnedAsync(options, token)
let! session =
owned.Value.CreateSessionAsync(
NewSessionRequest(Name = "demo", Command = "/bin/sh"),
token
)
// The new session's active window is its first; name it.
let! active =
session
|> Session.windows
|> Query.where (WindowFields.active |> Filter.eq true)
|> Query.list token
let! editor = active[0] |> Window.rename token "editor"
// Split its active pane; the new pane is on the right and stays
// in the background, so the left pane is still active.
let! left = editor |> Window.activePane token
let! right =
left
|> Pane.split
token
(SplitPaneRequest(Direction = PaneDirection.Right))
// A second window, also left in the background.
let! logs =
session |> Session.newWindow token (NewWindowRequest(Name = "logs"))
// Type a command and wait for what it prints, not for its echo.
let! waited =
right
|> Pane.sendAndWait
token
(TimeSpan.FromSeconds 10.)
"printf 'hello from %s\\n' tmux"
"hello from tmux"
// Select the right pane, then the logs window.
let! selected = right |> Pane.select token
let! current = logs |> Window.select token
// Walk a snapshot down from the server: sessions, windows, panes.
let! server = LibTmux.Server.ConnectAsync(options, token)
let! snapshot = server |> Server.capture token SnapshotDepth.Panes
let sessions = snapshot.Sessions
for session in sessions do
printfn "session %s" session.Name
let windows = session.Windows
for window in windows do
let panes = window.Panes
let ids = [ for pane in panes -> string pane.Id ]
printfn
" window %d:%s: %s"
window.Index
window.Name
(String.Join(" ", ids))
// Then up from one pane to its window and session.
let pane = snapshot.Panes |> Seq.find (fun pane -> pane.Id = right.Id)
let window = pane.Window
let owner = window.Session
printfn
"%O is in window %s of session %s"
pane.Id
window.Name
owner.Name
}
try
runAsync().GetAwaiter().GetResult()
with error ->
raise (InvalidOperationException(
"tmux quickstart failed", error))
Example details
No tmux server yet

tmux before the first call: no server is running.

No tmux server yet

tmux after Server.CreateOwnedAsync: no server is running.

%0 sh
[demo]

tmux after Server.CreateSessionAsync: added session demo.

%0 sh
[demo]

tmux after Query.list: unchanged.

%0 sh
[demo]

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

%0 sh
[demo]

tmux after Window.activePane: unchanged.

%0 sh
%1 sh
[demo]

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

%0 sh
%1 sh
[demo]

tmux after Session.newWindow: added window 1:logs.

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

tmux after Pane.sendAndWait: sent keys to pane %1; read pane %1.

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

tmux after Pane.select: selected pane %1 in window 0:editor.

%2 sh
[demo]

tmux after Window.select: selected window 1:logs.

%2 sh
[demo]

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

%2 sh
[demo]

tmux after Server.capture: unchanged.

%2 sh
[demo]

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

%2 sh
[demo]

tmux after Session.Windows: 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 Seq.find: unchanged, the call sent no command.

%2 sh
[demo]

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

%2 sh
[demo]

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

No sessions

tmux after OwnedServerScope.DisposeAsync: the server has exited.

  1. Before the first call

    No tmux server is running yet.

  2. Server.CreateOwnedAsync returned Task<OwnedServerScope>

    {
    "configFile": "/dev/null",
    "socketName": "fsharp-0123456789abcdef0123456789abcdef"
    }
    3 tmux commands, 1 that changes tmux
    1. list-sessions error connecting to /tmp/tmux-1000/fsharp-0123456789abcdef0123456789abcdef (No such file or directory)
    2. start-server no output
    3. list-sessions no server running on /tmp/tmux-1000/fsharp-0123456789abcdef0123456789abcdef

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

  3. Server.CreateSessionAsync returned Task<Session>

    {
    "id": "$0",
    "name": "demo"
    }
    3 tmux commands, 2 that change tmux
    1. new-session -P -F '#{pid}:#{start_time} #{session_id} #{window_id} #{pane_id} #{window_index}' -d -s demo -- /bin/sh 3226196:1793889101 $0 @0 %0 0
    2. attach-session -f ignore-size,no-output,new-layouts no output
    3. display-message -p -t $0 #{config_files}LT9b8ad2125ee24bdfb748c8#{line}LT9b8ad2125ee24bdfb748c8#{next_session_id}LT9b8ad2125ee24bdfb748c8#{pid}LT9b8ad2125ee24bdfb748c8#{socket_path}LT9b8ad2125ee24bdfb748c8#{start_time}LT9b8ad2125ee24bdfb748c8#{uid}LT9b8ad2125ee24bdfb748c8#{user}LT9b8ad2125ee24bdfb748c8#{version}LT9b8ad2125ee24bdfb748c8#{active_window_index}LT9b8ad2125ee24bdfb748c8#{last_window_ind… /dev/nullLT9b8ad2125ee24bdfb748c8LT9b8ad2125ee24bdfb748c8$1LT9b8ad2125ee24bdfb748c83226196LT9b8ad2125ee24bdfb748c8/tmp/tmux-1000/fsharp-0123456789abcdef0123456789abcdefLT9b8ad2125ee24bdfb748c81793889101LT9b8ad2125ee24bdfb748c81000LT9b8ad2125ee24bdfb748c8dLT9b8ad2125ee24bdfb748c83.8aLT9b8ad2125ee24bdfb748c80LT9b8ad2125ee24bdfb748c80LT9b8ad2125ee24bdfb748c81793889101LT9b8ad2125ee…

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

    1 notification from tmux while the call ran
    1. %session-changed $0 demo
  4. Query.list returned Task<IReadOnlyList<Window>>

    {
    "ids": [
    "@0"
    ]
    }
    1 tmux command
    1. list-windows -t $0 -f #{==:#{window_active},1} -F #{config_files}LT9b8ad2125ee24bdfb748c8#{line}LT9b8ad2125ee24bdfb748c8#{next_session_id}LT9b8ad2125ee24bdfb748c8#{pid}LT9b8ad2125ee24bdfb748c8#{socket_path}LT9b8ad2125ee24bdfb748c8#{start_time}LT9b8ad2125ee24bdfb748c8#{uid}LT9b8ad2125ee24bdfb748c8#{user}LT9b8ad2125ee24bdfb748c8#{version}LT9b8ad2125ee24bdfb748c8#{active_window_index}LT9b8ad2125ee24b… /dev/nullLT9b8ad2125ee24bdfb748c81LT9b8ad2125ee24bdfb748c8$1LT9b8ad2125ee24bdfb748c83226196LT9b8ad2125ee24bdfb748c8/tmp/tmux-1000/fsharp-0123456789abcdef0123456789abcdefLT9b8ad2125ee24bdfb748c81793889101LT9b8ad2125ee24bdfb748c81000LT9b8ad2125ee24bdfb748c8dLT9b8ad2125ee24bdfb748c83.8aLT9b8ad2125ee24bdfb748c80LT9b8ad2125ee24bdfb748c80LT9b8ad2125ee24bdfb748c81793889101LT9b8ad2125e…
  5. Window.rename returned Task<Window>

    {
    "id": "@0",
    "index": 0,
    "name": "editor"
    }
    2 tmux commands, 1 that changes tmux
    1. rename-window -t @0 -- editor no output
    2. display-message -p -t $0:0 #{config_files}LT9b8ad2125ee24bdfb748c8#{line}LT9b8ad2125ee24bdfb748c8#{next_session_id}LT9b8ad2125ee24bdfb748c8#{pid}LT9b8ad2125ee24bdfb748c8#{socket_path}LT9b8ad2125ee24bdfb748c8#{start_time}LT9b8ad2125ee24bdfb748c8#{uid}LT9b8ad2125ee24bdfb748c8#{user}LT9b8ad2125ee24bdfb748c8#{version}LT9b8ad2125ee24bdfb748c8#{active_window_index}LT9b8ad2125ee24bdfb748c8#{last_window_i… /dev/nullLT9b8ad2125ee24bdfb748c8LT9b8ad2125ee24bdfb748c8$1LT9b8ad2125ee24bdfb748c83226196LT9b8ad2125ee24bdfb748c8/tmp/tmux-1000/fsharp-0123456789abcdef0123456789abcdefLT9b8ad2125ee24bdfb748c81793889101LT9b8ad2125ee24bdfb748c81000LT9b8ad2125ee24bdfb748c8dLT9b8ad2125ee24bdfb748c83.8aLT9b8ad2125ee24bdfb748c80LT9b8ad2125ee24bdfb748c80LT9b8ad2125ee24bdfb748c81793889101LT9b8ad2125ee…
    1 notification from tmux while the call ran
    1. %window-renamed @0 editor
  6. Window.activePane returned Task<Pane>

    {
    "id": "%0"
    }
    1 tmux command
    1. list-panes -t $0:0 -f #{pane_active} -F #{config_files}LT9b8ad2125ee24bdfb748c8#{line}LT9b8ad2125ee24bdfb748c8#{next_session_id}LT9b8ad2125ee24bdfb748c8#{pid}LT9b8ad2125ee24bdfb748c8#{socket_path}LT9b8ad2125ee24bdfb748c8#{start_time}LT9b8ad2125ee24bdfb748c8#{uid}LT9b8ad2125ee24bdfb748c8#{user}LT9b8ad2125ee24bdfb748c8#{version}LT9b8ad2125ee24bdfb748c8#{active_window_index}LT9b8ad2125ee24bdfb748c8#{… /dev/nullLT9b8ad2125ee24bdfb748c81LT9b8ad2125ee24bdfb748c8$1LT9b8ad2125ee24bdfb748c83226196LT9b8ad2125ee24bdfb748c8/tmp/tmux-1000/fsharp-0123456789abcdef0123456789abcdefLT9b8ad2125ee24bdfb748c81793889101LT9b8ad2125ee24bdfb748c81000LT9b8ad2125ee24bdfb748c8dLT9b8ad2125ee24bdfb748c83.8aLT9b8ad2125ee24bdfb748c80LT9b8ad2125ee24bdfb748c80LT9b8ad2125ee24bdfb748c81793889101LT9b8ad2125e…
  7. Pane.split returned Task<Pane>

    {
    "id": "%1"
    }
    2 tmux commands, 1 that changes tmux
    1. split-window -P -F #{pane_id} -t %0 -h -d %1
    2. display-message -p -t %1 #{config_files}LT9b8ad2125ee24bdfb748c8#{line}LT9b8ad2125ee24bdfb748c8#{next_session_id}LT9b8ad2125ee24bdfb748c8#{pid}LT9b8ad2125ee24bdfb748c8#{socket_path}LT9b8ad2125ee24bdfb748c8#{start_time}LT9b8ad2125ee24bdfb748c8#{uid}LT9b8ad2125ee24bdfb748c8#{user}LT9b8ad2125ee24bdfb748c8#{version}LT9b8ad2125ee24bdfb748c8#{active_window_index}LT9b8ad2125ee24bdfb748c8#{last_window_ind… /dev/nullLT9b8ad2125ee24bdfb748c8LT9b8ad2125ee24bdfb748c8$1LT9b8ad2125ee24bdfb748c83226196LT9b8ad2125ee24bdfb748c8/tmp/tmux-1000/fsharp-0123456789abcdef0123456789abcdefLT9b8ad2125ee24bdfb748c81793889101LT9b8ad2125ee24bdfb748c81000LT9b8ad2125ee24bdfb748c8dLT9b8ad2125ee24bdfb748c83.8aLT9b8ad2125ee24bdfb748c80LT9b8ad2125ee24bdfb748c80LT9b8ad2125ee24bdfb748c81793889101LT9b8ad2125ee…
    1 notification from tmux while the call ran
    1. %layout-change @0 {"V":2,"L":{"t":"h","w":80,"h":24,"x":0,"y":0,"c":[{"t":"p","w":40,"h":24,"x":0,"y":0,"a":true,"i":0,"I":"%0"},{"t":"p","w":39,"h":24,"x":41,"y":0,"i":1,"I":"%1"}]}} {"V":2,"L":{"t":"h","w":80,"h":24,"x":0,"y":0,"c":[{"t":"p","w":40,"h":24,"x":0,"y":0,"a":true,"i":0,"I":"%0"},{"t":"p","w":39,"h":24,"x":41,"y":0,"i":1,"I":"%1"}]}} *
  8. Session.newWindow returned Task<Window>

    {
    "id": "@1",
    "index": 1,
    "name": "logs"
    }
    2 tmux commands, 1 that changes tmux
    1. new-window -P -F #{window_id} -d -t $0: -n logs @1
    2. list-windows -t $0 -F #{config_files}LT9b8ad2125ee24bdfb748c8#{line}LT9b8ad2125ee24bdfb748c8#{next_session_id}LT9b8ad2125ee24bdfb748c8#{pid}LT9b8ad2125ee24bdfb748c8#{socket_path}LT9b8ad2125ee24bdfb748c8#{start_time}LT9b8ad2125ee24bdfb748c8#{uid}LT9b8ad2125ee24bdfb748c8#{user}LT9b8ad2125ee24bdfb748c8#{version}LT9b8ad2125ee24bdfb748c8#{active_window_index}LT9b8ad2125ee24bdfb748c8#{last_window_index}… /dev/nullLT9b8ad2125ee24bdfb748c82LT9b8ad2125ee24bdfb748c8$1LT9b8ad2125ee24bdfb748c83226196LT9b8ad2125ee24bdfb748c8/tmp/tmux-1000/fsharp-0123456789abcdef0123456789abcdefLT9b8ad2125ee24bdfb748c81793889101LT9b8ad2125ee24bdfb748c81000LT9b8ad2125ee24bdfb748c8dLT9b8ad2125ee24bdfb748c83.8aLT9b8ad2125ee24bdfb748c80LT9b8ad2125ee24bdfb748c81LT9b8ad2125ee24bdfb748c81793889101LT9b8ad2125e…
    1 notification from tmux while the call ran
    1. %window-add @1
  9. Pane.sendAndWait returned Task<PaneWaitResult>

    {
    "found": true
    }
    19 tmux commands, 6 that change tmux
    1. attach-session -t $0 no output
    2. refresh-client -f new-layouts no output
    3. refresh-client -f ignore-size no output
    4. refresh-client -B libtmux-pane-dead:%*:#{pane_dead} no output
    5. list-panes -t $0:.%1 -F #{pane_id} -f #{==:#{pane_id},%1} %1
    6. display-message -t %1 -p -- '#{pane_pid} #{history_size} #{history_limit} #{pane_height} #{cursor_y} #{pane_dead} #{alternate_on} #{pane_width}' 3226401 0 2000 24 0 0 0 39
    7. capture-pane -t %1 -p $
    8. capture-pane -t %1 -p -J $
    9. display-message -t %1 -p -- '#{pane_pid} #{history_size} #{history_limit} #{pane_height} #{cursor_y} #{pane_dead} #{alternate_on} #{pane_width}' 3226401 0 2000 24 0 0 0 39
    10. send-keys -t %1 -l -- 'printf '\''hello from %s\n'\'' tmux' no output
    11. send-keys -t %1 Enter no output
    12. display-message -t %1 -p -- '#{pane_pid} #{history_size} #{history_limit} #{pane_height} #{cursor_y} #{pane_dead} #{alternate_on} #{pane_width}' 3226401 0 2000 24 2 0 0 39
    13. capture-pane -t %1 -p -S 0 $ printf 'hello from %s\n' tmux hello from tmux $
    14. capture-pane -t %1 -p -S 0 -J $ printf 'hello from %s\n' tmux hello from tmux $
    15. display-message -t %1 -p -- '#{pane_pid} #{history_size} #{history_limit} #{pane_height} #{cursor_y} #{pane_dead} #{alternate_on} #{pane_width}' 3226401 0 2000 24 2 0 0 39
    16. display-message -t %1 -p -- '#{pane_pid} #{history_size} #{history_limit} #{pane_height} #{cursor_y} #{pane_dead} #{alternate_on} #{pane_width}' 3226401 0 2000 24 2 0 0 39
    17. capture-pane -t %1 -p $ printf 'hello from %s\n' tmux hello from tmux $
    18. capture-pane -t %1 -p -J $ printf 'hello from %s\n' tmux hello from tmux $
    19. display-message -t %1 -p -- '#{pane_pid} #{history_size} #{history_limit} #{pane_height} #{cursor_y} #{pane_dead} #{alternate_on} #{pane_width}' 3226401 0 2000 24 2 0 0 39

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

    6 notifications from tmux while the call ran
    1. %client-session-changed client-3226620 $0 demo
    2. %session-changed $0 demo
    3. %output %1 printf 'hello from %s\134n' tmux
    4. %output %1 \015\012hello from tmux\015\012$
    5. %exit
    6. %client-detached client-3226620
  10. Pane.select returned Task<Pane>

    {
    "id": "%1"
    }
    2 tmux commands, 1 that changes tmux
    1. select-pane -t %1 no output
    2. display-message -p -t $0:.%1 #{config_files}LT9b8ad2125ee24bdfb748c8#{line}LT9b8ad2125ee24bdfb748c8#{next_session_id}LT9b8ad2125ee24bdfb748c8#{pid}LT9b8ad2125ee24bdfb748c8#{socket_path}LT9b8ad2125ee24bdfb748c8#{start_time}LT9b8ad2125ee24bdfb748c8#{uid}LT9b8ad2125ee24bdfb748c8#{user}LT9b8ad2125ee24bdfb748c8#{version}LT9b8ad2125ee24bdfb748c8#{active_window_index}LT9b8ad2125ee24bdfb748c8#{last_window… /dev/nullLT9b8ad2125ee24bdfb748c8LT9b8ad2125ee24bdfb748c8$1LT9b8ad2125ee24bdfb748c83226196LT9b8ad2125ee24bdfb748c8/tmp/tmux-1000/fsharp-0123456789abcdef0123456789abcdefLT9b8ad2125ee24bdfb748c81793889101LT9b8ad2125ee24bdfb748c81000LT9b8ad2125ee24bdfb748c8dLT9b8ad2125ee24bdfb748c83.8aLT9b8ad2125ee24bdfb748c80LT9b8ad2125ee24bdfb748c81LT9b8ad2125ee24bdfb748c81793889104LT9b8ad2125ee…
    1 notification from tmux while the call ran
    1. %window-pane-changed @0 %1
  11. Window.select returned Task<Window>

    {
    "id": "@1",
    "index": 1,
    "name": "logs"
    }
    2 tmux commands, 1 that changes tmux
    1. select-window -t @1 no output
    2. display-message -p -t $0:1 #{config_files}LT9b8ad2125ee24bdfb748c8#{line}LT9b8ad2125ee24bdfb748c8#{next_session_id}LT9b8ad2125ee24bdfb748c8#{pid}LT9b8ad2125ee24bdfb748c8#{socket_path}LT9b8ad2125ee24bdfb748c8#{start_time}LT9b8ad2125ee24bdfb748c8#{uid}LT9b8ad2125ee24bdfb748c8#{user}LT9b8ad2125ee24bdfb748c8#{version}LT9b8ad2125ee24bdfb748c8#{active_window_index}LT9b8ad2125ee24bdfb748c8#{last_window_i… /dev/nullLT9b8ad2125ee24bdfb748c8LT9b8ad2125ee24bdfb748c8$1LT9b8ad2125ee24bdfb748c83226196LT9b8ad2125ee24bdfb748c8/tmp/tmux-1000/fsharp-0123456789abcdef0123456789abcdefLT9b8ad2125ee24bdfb748c81793889101LT9b8ad2125ee24bdfb748c81000LT9b8ad2125ee24bdfb748c8dLT9b8ad2125ee24bdfb748c83.8aLT9b8ad2125ee24bdfb748c81LT9b8ad2125ee24bdfb748c81LT9b8ad2125ee24bdfb748c81793889104LT9b8ad2125ee…
    1 notification from tmux while the call ran
    1. %session-window-changed $0 @1
  12. Server.ConnectAsync returned Task<Server>

    {
    "socketName": "fsharp-0123456789abcdef0123456789abcdef"
    }

    The call sent no tmux command.

  13. Server.capture returned Task<Server>

    {
    "panes": 3,
    "sessions": 1,
    "windows": 2
    }
    3 tmux commands
    1. list-sessions -F #{config_files}LT9b8ad2125ee24bdfb748c8#{line}LT9b8ad2125ee24bdfb748c8#{next_session_id}LT9b8ad2125ee24bdfb748c8#{pid}LT9b8ad2125ee24bdfb748c8#{socket_path}LT9b8ad2125ee24bdfb748c8#{start_time}LT9b8ad2125ee24bdfb748c8#{uid}LT9b8ad2125ee24bdfb748c8#{user}LT9b8ad2125ee24bdfb748c8#{version}LT9b8ad2125ee24bdfb748c8#{active_window_index}LT9b8ad2125ee24bdfb748c8#{last_window_index}LT9b8… /dev/nullLT9b8ad2125ee24bdfb748c80LT9b8ad2125ee24bdfb748c8$1LT9b8ad2125ee24bdfb748c83226196LT9b8ad2125ee24bdfb748c8/tmp/tmux-1000/fsharp-0123456789abcdef0123456789abcdefLT9b8ad2125ee24bdfb748c81793889101LT9b8ad2125ee24bdfb748c81000LT9b8ad2125ee24bdfb748c8dLT9b8ad2125ee24bdfb748c83.8aLT9b8ad2125ee24bdfb748c81LT9b8ad2125ee24bdfb748c81LT9b8ad2125ee24bdfb748c81793889104LT9b8ad2125e…
    2. list-windows -a -F #{config_files}LT9b8ad2125ee24bdfb748c8#{line}LT9b8ad2125ee24bdfb748c8#{next_session_id}LT9b8ad2125ee24bdfb748c8#{pid}LT9b8ad2125ee24bdfb748c8#{socket_path}LT9b8ad2125ee24bdfb748c8#{start_time}LT9b8ad2125ee24bdfb748c8#{uid}LT9b8ad2125ee24bdfb748c8#{user}LT9b8ad2125ee24bdfb748c8#{version}LT9b8ad2125ee24bdfb748c8#{active_window_index}LT9b8ad2125ee24bdfb748c8#{last_window_index}LT9… /dev/nullLT9b8ad2125ee24bdfb748c82LT9b8ad2125ee24bdfb748c8$1LT9b8ad2125ee24bdfb748c83226196LT9b8ad2125ee24bdfb748c8/tmp/tmux-1000/fsharp-0123456789abcdef0123456789abcdefLT9b8ad2125ee24bdfb748c81793889101LT9b8ad2125ee24bdfb748c81000LT9b8ad2125ee24bdfb748c8dLT9b8ad2125ee24bdfb748c83.8aLT9b8ad2125ee24bdfb748c81LT9b8ad2125ee24bdfb748c81LT9b8ad2125ee24bdfb748c81793889104LT9b8ad2125e…
    3. list-panes -a -F #{config_files}LT9b8ad2125ee24bdfb748c8#{line}LT9b8ad2125ee24bdfb748c8#{next_session_id}LT9b8ad2125ee24bdfb748c8#{pid}LT9b8ad2125ee24bdfb748c8#{socket_path}LT9b8ad2125ee24bdfb748c8#{start_time}LT9b8ad2125ee24bdfb748c8#{uid}LT9b8ad2125ee24bdfb748c8#{user}LT9b8ad2125ee24bdfb748c8#{version}LT9b8ad2125ee24bdfb748c8#{active_window_index}LT9b8ad2125ee24bdfb748c8#{last_window_index}LT9b8… /dev/nullLT9b8ad2125ee24bdfb748c82LT9b8ad2125ee24bdfb748c8$1LT9b8ad2125ee24bdfb748c83226196LT9b8ad2125ee24bdfb748c8/tmp/tmux-1000/fsharp-0123456789abcdef0123456789abcdefLT9b8ad2125ee24bdfb748c81793889101LT9b8ad2125ee24bdfb748c81000LT9b8ad2125ee24bdfb748c8dLT9b8ad2125ee24bdfb748c83.8aLT9b8ad2125ee24bdfb748c81LT9b8ad2125ee24bdfb748c81LT9b8ad2125ee24bdfb748c81793889104LT9b8ad2125e…
  14. Server.Sessions returned CapturedRelation<Session>

    {
    "ids": [
    "$0"
    ]
    }

    The call sent no tmux command.

  15. Session.Windows returned CapturedRelation<Window>

    {
    "ids": [
    "@0",
    "@1"
    ]
    }

    The call sent no tmux command.

  16. Window.Panes returned CapturedRelation<Pane>

    {
    "ids": [
    "%0",
    "%1"
    ]
    }

    The call sent no tmux command.

  17. Window.Panes returned CapturedRelation<Pane>

    {
    "ids": [
    "%2"
    ]
    }

    The call sent no tmux command.

  18. Seq.find returned Pane

    {
    "id": "%1"
    }

    The call sent no tmux command.

  19. Pane.Window returned Window

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

    The call sent no tmux command.

  20. Window.Session returned Session

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

    The call sent no tmux command.

  21. OwnedServerScope.DisposeAsync returned ValueTask

    null
    2 tmux commands, 1 that changes tmux
    1. display-message -p #{pid} 3226196
    2. kill-server no output

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

    1 notification from tmux while the call ran
    1. %exit
1/20
Run this example

.NET SDK 10.0.303, .NET 8 and 10 runtimes, tmux 3.4 or newer on Linux/macOS

Save the program above as app/Program.fs 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. Error handling adds diagnostics; every version checks required results and deadlines.

app/Example.fsproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
<LangVersion>10.0</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<DisableImplicitFSharpCoreReference>true</DisableImplicitFSharpCoreReference>
<DisableImplicitLibraryPacksFolder>true</DisableImplicitLibraryPacksFolder>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
<PackageReference Include="FSharp.Core" Version="[10.1.303]" />
<PackageReference Include="LibTmux.FSharp" Version="[0.1.1]" />
</ItemGroup>
</Project>
app/global.json
{
"sdk": {
"version": "10.0.303",
"rollForward": "disable",
"allowPrerelease": false
},
"test": {
"runner": "Microsoft.Testing.Platform"
}
}

Setup and run

# Save the files above at their displayed relative paths.
cd app
dotnet restore Example.fsproj
dotnet build Example.fsproj -c Release --no-restore --warnaserror
export TMUX_TMPDIR=/tmp/libtmux-dotnet-dev
mkdir -p "$TMUX_TMPDIR"
unset TMUX TMUX_PANE
dotnet bin/Release/net8.0/Example.dll
dotnet bin/Release/net10.0/Example.dll

Expected output

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

Install LibTmux.FSharp

From Git
Terminal
Package Manager Console
.fsproj
Directory.Packages.props
Terminal
F# script
app.cs
build.cake
Terminal
LibTmux.FSharp 0.1.1 0.x NuGet
$ dotnet package add LibTmux.FSharp --version 0.1.1
PM> NuGet\Install-Package LibTmux.FSharp -Version 0.1.1
<PackageReference Include="LibTmux.FSharp" Version="0.1.1" />
<Project>
  <PropertyGroup>
    <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
  </PropertyGroup>
  <ItemGroup>
    <PackageVersion Include="LibTmux.FSharp" Version="0.1.1" />
  </ItemGroup>
</Project>
Project file (.csproj or .fsproj)
<PackageReference Include="LibTmux.FSharp" />
$ paket add LibTmux.FSharp --version 0.1.1 --interactive
#r "nuget: LibTmux.FSharp, 0.1.1"
#:package LibTmux.FSharp@0.1.1
#addin nuget:?package=LibTmux.FSharp&version=0.1.1&loaddependencies=true
$ dotnet add reference ../libtmux-dotnet/src/LibTmux.FSharp/LibTmux.FSharp.fsproj

.NET 10 SDK: run in your project directory. On .NET 8 or 9, use dotnet add package with the same arguments.

Run in Visual Studio on Windows, in Tools > NuGet Package Manager > Package Manager Console. Choose the target project in that console.

Add this inside an ItemGroup in your .csproj or .fsproj, then run dotnet restore. For central version management, use the CPM tab.

Save Directory.Packages.props at the solution root, or merge these settings into the existing file. Add the versionless reference inside the project’s ItemGroup, then run dotnet restore.

Requires Paket and a solution initialized with paket init. The interactive prompt selects the projects that should reference the package.

Use in an F# .fsx script, dotnet fsi, or a Polyglot Notebook with NuGet support, on .NET 8 or later. This is not a directive for an ordinary compiled project.

C# file-based apps require the .NET 10 SDK. Place this at the top of a .cs file, before code, then run dotnet run app.cs. F# scripts use the Script & interactive tab.

Use Cake.Tool 6 or later for a .cake script on .NET 8 or later, with Cake’s in-process NuGet client enabled. This loads the library and its dependencies; it has no Cake task aliases or executable tool. Cake Frosting projects use PackageReference.

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

API references

Esc
Search in

Type to search.

Reference previewOpen reference