# LibTmux.set_hook

- **Module:** LibTmux
- **Package:** LibTmux
- **Language:** Julia
- **Kind:** function
- **Source:** https://github.com/libtmux/libtmux-julia/blob/f3da513be1225d36d5854cd8db5972c01857578e/src/configuration.jl#L448
- **Page:** https://libtmux.org/en/julia/latest/reference/libtmux-set_hook/

```
set_hook(
    connection::LibTmux.ControlConnection,
    scope,
    name::AbstractString,
    command::AbstractString;
    index,
    kwargs...
)

set_hook(
    server::LibTmux.Server,
    scope,
    name::AbstractString,
    command::AbstractString;
    index,
    kwargs...
)
```

## Methods

### `set_hook` (overload 1)

```julia
set_hook(
    connection::LibTmux.ControlConnection,
    scope,
    name::AbstractString,
    command::AbstractString;
    index,
    kwargs...
)
```

[Source](https://github.com/libtmux/libtmux-julia/blob/f3da513be1225d36d5854cd8db5972c01857578e/src/control_options.jl#L359).

Store tmux command grammar using literal unquoted command names and printable arguments, single/double quotes, literal punctuation escapes and semicolon sequences. Environment/tilde expansion, comments, command blocks and decoded control escapes are refused before writing. Single quotes preserve literal backslash and dollar text. This is a deliberately bounded storage grammar; commands must also obey the connection's trusted hook contract when executed.

```julia
set_hook(connection::ControlConnection, scope, name, command; index=nothing, kwargs...)
```



Without `index`, replace the whole array; an empty body masks inherited hooks. An indexed empty body is invalid. tmux may clear a whole array before reporting a command parse error. Return `ControlResult` without rollback or replay.

### `set_hook` (overload 2)

```julia
set_hook(
    server::LibTmux.Server,
    scope,
    name::AbstractString,
    command::AbstractString;
    index,
    kwargs...
)
```

[Source](https://github.com/libtmux/libtmux-julia/blob/f3da513be1225d36d5854cd8db5972c01857578e/src/configuration.jl#L459).

Store executable tmux command grammar; this is not a shell command or literal option value. tmux parses the body when stored and executes it when the hook fires. Without `index`, replace the whole command array; an empty body clears it and masks inherited hooks. A numeric index changes only that sparse entry. Return `CommandResult`; parsing failures retain tmux's command error evidence. tmux may clear an existing whole array before reporting a parse failure. The library does not roll back or retry this mutation.

```julia
set_hook(server, scope, name, command; index=nothing, kwargs...)
```

## Parameters

- `connection` (`LibTmux.ControlConnection`) (for `set_hook(connection, scope, name, command, index, kwargs)`)
- `scope` (`Any`)
- `name` (`AbstractString`)
- `command` (`AbstractString`)
- `index`
  Default: `nothing`.
- `kwargs`
- `server` (`LibTmux.Server`) (for `set_hook(server, scope, name, command, index, kwargs)`)
