Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ Notable changes to `libtmux`.
its body returns, fails or is cancelled. (#103)
- Runtime: `Runtime:with_server(options, body)` runs the body on a private
server and stops it however the body ends. (#103)
- Runtime requests find tmux on the caller's `PATH` when `binary` is omitted.
Pass an absolute `binary` to select another build. `Runtime:find_tmux`
returns the discovered path as a Request. (#109)
- Examples: each program starts and stops its own server, so
`examples/api/run.sh`, which needed `sh` and `perl`, is removed. Run a program
with `lua examples/api/connect.lua`; `TMUX_BIN` still selects another tmux,
and `TMUX_SOCKET` is no longer read. (#103)
with `lua examples/api/connect.lua`. The programs find tmux on `PATH`
and no longer read `TMUX_SOCKET`. (#103, #109)
- Docs: the README shows `Pane:resize` and `Window:resize` with a new tested
program, `examples/api/resize.lua`, and links the kill, option and hook
methods.
Expand Down
46 changes: 10 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,8 @@ local function must(value, err)
return value
end

-- tmux is /usr/bin/tmux unless TMUX_BIN names another absolute path.
local binary = os.getenv("TMUX_BIN") or "/usr/bin/tmux"

must(adapter.run(function(runtime)
local owned = must(runtime:start_server({ binary = binary }):await())
local owned = must(runtime:start_server():await())
local created = must(owned.server
:new_session({
name = "demo",
Expand All @@ -103,8 +100,7 @@ Live calls return [Requests][ref-request]. [`:await()`][ref-request-await]
yields inside the [runtime][ref-runtime] body and returns `value, err`; `must`
raises the error.

The programs use `/usr/bin/tmux`. Set `TMUX_BIN` to another absolute path to
change that. Run one from a checkout:
Put tmux on `PATH` and run one of the programs from a checkout:

```console
$ git clone https://github.com/libtmux/libtmux-lua.git && cd libtmux-lua
Expand Down Expand Up @@ -139,12 +135,9 @@ local function must(value, err)
return value
end

-- tmux is /usr/bin/tmux unless TMUX_BIN names another absolute path.
local binary = os.getenv("TMUX_BIN") or "/usr/bin/tmux"

must(adapter.run(function(runtime)
-- The server is private: its own directory, socket and environment.
local owned = must(runtime:start_server({ binary = binary }):await())
local owned = must(runtime:start_server():await())
local server = owned.server
local before = must(server:snapshot():await())

Expand Down Expand Up @@ -185,11 +178,8 @@ local function must(value, err)
return value
end

-- tmux is /usr/bin/tmux unless TMUX_BIN names another absolute path.
local binary = os.getenv("TMUX_BIN") or "/usr/bin/tmux"

must(adapter.run(function(runtime)
local owned = must(runtime:start_server({ binary = binary }):await())
local owned = must(runtime:start_server():await())
local server = owned.server
must(server:new_session({ name = "demo", argv = { "/bin/cat" } }):await())
local snapshot = must(server:snapshot({ strict = true }):await())
Expand Down Expand Up @@ -385,11 +375,8 @@ local function must(value, err)
return value
end

-- tmux is /usr/bin/tmux unless TMUX_BIN names another absolute path.
local binary = os.getenv("TMUX_BIN") or "/usr/bin/tmux"

must(adapter.run(function(runtime)
local owned = must(runtime:start_server({ binary = binary }):await())
local owned = must(runtime:start_server():await())
local created = must(owned.server
:new_session({
name = "demo",
Expand Down Expand Up @@ -471,11 +458,8 @@ local function must(value, err)
return value
end

-- tmux is /usr/bin/tmux unless TMUX_BIN names another absolute path.
local binary = os.getenv("TMUX_BIN") or "/usr/bin/tmux"

must(adapter.run(function(runtime)
local owned = must(runtime:start_server({ binary = binary }):await())
local owned = must(runtime:start_server():await())
local session = { name = "demo", argv = { "/bin/sh" } }
local created = must(owned.server:new_session(session):await())
local pane = created.pane
Expand Down Expand Up @@ -583,11 +567,8 @@ local function must(value, err)
return value
end

-- tmux is /usr/bin/tmux unless TMUX_BIN names another absolute path.
local binary = os.getenv("TMUX_BIN") or "/usr/bin/tmux"

must(adapter.run(function(runtime)
local owned = must(runtime:start_server({ binary = binary }):await())
local owned = must(runtime:start_server():await())
local session = { name = "demo", argv = { "/bin/cat" } }
local created = must(owned.server:new_session(session):await())
local split_opts = { direction = "right", argv = { "/bin/cat" } }
Expand Down Expand Up @@ -654,11 +635,8 @@ local function must(value, err)
return value
end

-- tmux is /usr/bin/tmux unless TMUX_BIN names another absolute path.
local binary = os.getenv("TMUX_BIN") or "/usr/bin/tmux"

must(adapter.run(function(runtime)
local owned = must(runtime:start_server({ binary = binary }):await())
local owned = must(runtime:start_server():await())
-- One tmux process runs all four commands, in order.
local done = must(owned.server
:group({
Expand Down Expand Up @@ -715,11 +693,8 @@ local function must(value, err)
return value
end

-- tmux is /usr/bin/tmux unless TMUX_BIN names another absolute path.
local binary = os.getenv("TMUX_BIN") or "/usr/bin/tmux"

must(adapter.run(function(runtime)
local owned = must(runtime:start_server({ binary = binary }):await())
local owned = must(runtime:start_server():await())
local created = must(owned.server
:new_session({
name = "demo",
Expand Down Expand Up @@ -769,8 +744,7 @@ did not create stay open:
local adapter = require("libtmux.runtime.nvim")

return adapter.start(function(runtime)
local binary = vim.fn.exepath("tmux")
local owned, err = runtime:start_server({ binary = binary }):await()
local owned, err = runtime:start_server():await()
if not owned then
return nil, err
end
Expand Down
2 changes: 1 addition & 1 deletion docs/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ session stores.
```lua
local adapter = require("libtmux.runtime.luv")
local result, err = adapter.run(function(runtime)
local owned = assert(runtime:start_server({ binary = "/usr/bin/tmux" }):await())
local owned = assert(runtime:start_server():await())
local server = owned.server
local created = assert(server:new_session({ name = "demo", argv = { "/bin/cat" } }):await())
local session = created.session
Expand Down
15 changes: 14 additions & 1 deletion docs/runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@ Choose an adapter:
callbacks outside fast events. `on_done(value, err)` runs after owned cleanup;
unrelated host handles stay open.

## Choose the tmux executable

`connect`, `start_server` and `with_server` use the first executable regular
file named `tmux` on the caller's `PATH`. Each request captures `PATH` and the
current directory at submission and reuses the selected absolute path. With
`PATH` unset, the lookup checks `/usr/bin` and `/bin`. An empty entry checks the
captured working directory.

Pass an absolute `binary` to select a particular build. Use
`runtime:find_tmux():await()` to get the path without launching tmux or
contacting a server. A search with no executable returns `invalid_endpoint`
before sending a command.

## Start a private server

`runtime:start_server(options):await()` starts a tmux server this runtime owns
Expand All @@ -28,7 +41,7 @@ that already runs. The tested programs are

| Option | Default | Meaning |
| --- | --- | --- |
| `binary` | required | Absolute tmux executable |
| `binary` | tmux on `PATH` | Absolute tmux executable override |
| `config` | `/dev/null` | Absolute configuration file; the default loads none |
| `root` | system temporary directory | Absolute directory that holds the private one |
| `environment` | none | `NAME = value` entries for the daemon and its panes |
Expand Down
5 changes: 3 additions & 2 deletions docs/snapshots.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ and prints each pane and its window ID.

## Connect to a server

- Pass an absolute `binary` and, usually, an absolute `socket_path`.
`config_path` defaults to `/dev/null`.
- Pass an absolute `socket_path` to select the daemon. The client uses
[tmux on `PATH`](runtime.md#choose-the-tmux-executable) unless you pass
an absolute `binary`. `config_path` defaults to `/dev/null`.
- `connect` never starts a server;
[`start_server`](runtime.md#start-a-private-server) starts a private one.
Importing the library and reading captured records do no I/O.
Expand Down
7 changes: 3 additions & 4 deletions examples/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ Each Lua file is a standalone program. It starts its own private tmux
server with `Runtime:start_server`, uses it and stops it, even when the program
fails. No existing session is needed.

Needs Lua, LuaRocks, Git, tmux 3.3a or newer, a C compiler and CMake on Linux.
The programs use `/usr/bin/tmux`; set `TMUX_BIN` to another absolute path to
change that. From the repository root, install the library and its standalone
runtime dependency into a local tree:
Needs Lua, LuaRocks, Git, tmux 3.3a or newer on `PATH`, a C compiler and
CMake on Linux. From the repository root, install the library and its
standalone runtime dependency into a local tree:

```console
$ luarocks --tree ./rocks install luv 1.52.1-0 && \
Expand Down
5 changes: 1 addition & 4 deletions examples/api/capture.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ local function must(value, err)
return value
end

-- tmux is /usr/bin/tmux unless TMUX_BIN names another absolute path.
local binary = os.getenv("TMUX_BIN") or "/usr/bin/tmux"

must(adapter.run(function(runtime)
local owned = must(runtime:start_server({ binary = binary }):await())
local owned = must(runtime:start_server():await())
local session = { name = "demo", argv = { "/bin/sh" } }
local created = must(owned.server:new_session(session):await())
local pane = created.pane
Expand Down
7 changes: 2 additions & 5 deletions examples/api/connect.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@ local function must(value, err)
return value
end

-- tmux is /usr/bin/tmux unless TMUX_BIN names another absolute path.
local binary = os.getenv("TMUX_BIN") or "/usr/bin/tmux"

must(adapter.run(function(runtime)
local owned = must(runtime:start_server({ binary = binary }):await())
local owned = must(runtime:start_server():await())
local session = { name = "demo", argv = { "/bin/cat" } }
must(owned.server:new_session(session):await())

-- A second handle reaches the same daemon and leaves it running on close.
local target = { binary = binary, socket_path = owned.socket_path }
local target = { socket_path = owned.socket_path }
local server = must(runtime:connect(target):await())
local snapshot = must(server:snapshot({ strict = true }):await())
local demo = snapshot.sessions:where({ name = "demo" })
Expand Down
5 changes: 1 addition & 4 deletions examples/api/explain.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ local function must(value, err)
return value
end

-- tmux is /usr/bin/tmux unless TMUX_BIN names another absolute path.
local binary = os.getenv("TMUX_BIN") or "/usr/bin/tmux"

must(adapter.run(function(runtime)
local owned = must(runtime:start_server({ binary = binary }):await())
local owned = must(runtime:start_server():await())
local server = owned.server
local where = { active = true, current_command = "cat" }
for _, mode in ipairs({ "never", "auto" }) do
Expand Down
5 changes: 1 addition & 4 deletions examples/api/group.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ local function must(value, err)
return value
end

-- tmux is /usr/bin/tmux unless TMUX_BIN names another absolute path.
local binary = os.getenv("TMUX_BIN") or "/usr/bin/tmux"

must(adapter.run(function(runtime)
local owned = must(runtime:start_server({ binary = binary }):await())
local owned = must(runtime:start_server():await())
-- One tmux process runs all four commands, in order.
local done = must(owned.server
:group({
Expand Down
5 changes: 1 addition & 4 deletions examples/api/new_session.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ local function must(value, err)
return value
end

-- tmux is /usr/bin/tmux unless TMUX_BIN names another absolute path.
local binary = os.getenv("TMUX_BIN") or "/usr/bin/tmux"

must(adapter.run(function(runtime)
local owned = must(runtime:start_server({ binary = binary }):await())
local owned = must(runtime:start_server():await())
local created = must(owned.server
:new_session({
name = "demo",
Expand Down
5 changes: 1 addition & 4 deletions examples/api/new_window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ local function must(value, err)
return value
end

-- tmux is /usr/bin/tmux unless TMUX_BIN names another absolute path.
local binary = os.getenv("TMUX_BIN") or "/usr/bin/tmux"

must(adapter.run(function(runtime)
local owned = must(runtime:start_server({ binary = binary }):await())
local owned = must(runtime:start_server():await())
local created = must(owned.server
:new_session({
name = "demo",
Expand Down
5 changes: 1 addition & 4 deletions examples/api/query.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ local function must(value, err)
return value
end

-- tmux is /usr/bin/tmux unless TMUX_BIN names another absolute path.
local binary = os.getenv("TMUX_BIN") or "/usr/bin/tmux"

must(adapter.run(function(runtime)
local owned = must(runtime:start_server({ binary = binary }):await())
local owned = must(runtime:start_server():await())
local server = owned.server
must(server
:new_session({
Expand Down
5 changes: 1 addition & 4 deletions examples/api/refresh.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ local function must(value, err)
return value
end

-- tmux is /usr/bin/tmux unless TMUX_BIN names another absolute path.
local binary = os.getenv("TMUX_BIN") or "/usr/bin/tmux"

must(adapter.run(function(runtime)
local owned = must(runtime:start_server({ binary = binary }):await())
local owned = must(runtime:start_server():await())
local created = must(owned.server
:new_session({
name = "demo",
Expand Down
5 changes: 1 addition & 4 deletions examples/api/resize.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ local function must(value, err)
return value
end

-- tmux is /usr/bin/tmux unless TMUX_BIN names another absolute path.
local binary = os.getenv("TMUX_BIN") or "/usr/bin/tmux"

must(adapter.run(function(runtime)
local owned = must(runtime:start_server({ binary = binary }):await())
local owned = must(runtime:start_server():await())
local session = { name = "demo", argv = { "/bin/cat" } }
local created = must(owned.server:new_session(session):await())
local split_opts = { direction = "right", argv = { "/bin/cat" } }
Expand Down
5 changes: 1 addition & 4 deletions examples/api/send_keys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ local function must(value, err)
return value
end

-- tmux is /usr/bin/tmux unless TMUX_BIN names another absolute path.
local binary = os.getenv("TMUX_BIN") or "/usr/bin/tmux"

must(adapter.run(function(runtime)
local owned = must(runtime:start_server({ binary = binary }):await())
local owned = must(runtime:start_server():await())
local session = { name = "demo", argv = { "/bin/sh" } }
local created = must(owned.server:new_session(session):await())
local pane = created.pane
Expand Down
5 changes: 1 addition & 4 deletions examples/api/snapshot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ local function must(value, err)
return value
end

-- tmux is /usr/bin/tmux unless TMUX_BIN names another absolute path.
local binary = os.getenv("TMUX_BIN") or "/usr/bin/tmux"

must(adapter.run(function(runtime)
local owned = must(runtime:start_server({ binary = binary }):await())
local owned = must(runtime:start_server():await())
local server = owned.server
must(server
:new_session({
Expand Down
5 changes: 1 addition & 4 deletions examples/api/start_server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@ local function must(value, err)
return value
end

-- tmux is /usr/bin/tmux unless TMUX_BIN names another absolute path.
local binary = os.getenv("TMUX_BIN") or "/usr/bin/tmux"

must(adapter.run(function(runtime)
-- The server is private: its own directory, socket and environment.
local owned = must(runtime:start_server({ binary = binary }):await())
local owned = must(runtime:start_server():await())
local server = owned.server
local before = must(server:snapshot():await())

Expand Down
5 changes: 1 addition & 4 deletions examples/api/unsupported_version.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ local function must(value, err)
return value
end

-- tmux is /usr/bin/tmux unless TMUX_BIN names another absolute path.
local binary = os.getenv("TMUX_BIN") or "/usr/bin/tmux"

-- A stand-in for a tmux 3.1 server: a Lua script that answers the version
-- check with the usage error that release prints, so the refusal needs no old
-- tmux build. Its first line runs it with the interpreter running this program.
Expand All @@ -26,7 +23,7 @@ assert(uv.fs_chmod(stand_in, 448))

local ok, failure = pcall(function()
must(adapter.run(function(runtime)
local owned = must(runtime:start_server({ binary = binary }):await())
local owned = must(runtime:start_server():await())
local target = { binary = stand_in, socket_path = owned.socket_path }
local server, err = runtime:connect(target):await()
assert(server == nil, "a tmux before 3.2 was accepted")
Expand Down
5 changes: 1 addition & 4 deletions examples/api/wait_for_text.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ local function must(value, err)
return value
end

-- tmux is /usr/bin/tmux unless TMUX_BIN names another absolute path.
local binary = os.getenv("TMUX_BIN") or "/usr/bin/tmux"

must(adapter.run(function(runtime)
local owned = must(runtime:start_server({ binary = binary }):await())
local owned = must(runtime:start_server():await())
local session = { name = "demo", argv = { "/bin/sh" } }
local created = must(owned.server:new_session(session):await())
local pane = created.pane
Expand Down
Loading
Loading