# LibTmux\Set-TmuxHook

- **Package:** LibTmux
- **Language:** PowerShell
- **Kind:** function
- **Source:** https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/src/LibTmux.PowerShell/SetTmuxHookCommand.cs#L7
- **Page:** https://libtmux.org/en/powershell/latest/reference/libtmux-set-tmuxhook/

```
Pane:
Set-TmuxHook
    [-Pane] <LibTmux.Pane>
    -Name <System.String>
    [-Scope <System.Nullable[LibTmux.OptionScope]>]
    [-Global]
    -Command <System.String>
    [-Append]
    [-PassThru]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

Server (default):
Set-TmuxHook
    [-Server] <LibTmux.Server>
    -Name <System.String>
    [-Scope <System.Nullable[LibTmux.OptionScope]>]
    [-Global]
    -Command <System.String>
    [-Append]
    [-PassThru]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

Session:
Set-TmuxHook
    [-Session] <LibTmux.Session>
    -Name <System.String>
    [-Scope <System.Nullable[LibTmux.OptionScope]>]
    [-Global]
    -Command <System.String>
    [-Append]
    [-PassThru]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]

Window:
Set-TmuxHook
    [-Window] <LibTmux.Window>
    -Name <System.String>
    [-Scope <System.Nullable[LibTmux.OptionScope]>]
    [-Global]
    -Command <System.String>
    [-Append]
    [-PassThru]
    [-WhatIf]
    [-Confirm]
    [<CommonParameters>]
```

Set a hook entry and optionally return its grouped readback.

Pass a tmux command string to one hook or indexed entry. tmux normalizes the
stored command text; native readback keeps that syntax unchanged so it can be
supplied again. An unindexed set replaces existing entries. Append keeps existing
entries and lets tmux select a free index; use explicit indices when order matters.
PassThru emits the whole grouped hook readback. [`WhatIf`](/en/powershell/latest/reference/libtmux-set-tmuxhook/#LibTmux%5CSet-TmuxHook.parameter.WhatIf) performs no tmux I/O.

### Notes

[`Server`](/en/csharp/latest/reference/libtmux-server/) hooks are the global hook table; tmux has no separate server hook table.
Choose a hook supported by the selected scope. Scope and Global pass through to
tmux without remapping the owner. Empty pipelines do no I/O. Errors retain the
native owner and core exception; Continue permits later owners and Stop terminates.
Cancellation cannot undo commands already dispatched. Multiple mutations are
sequential, not an atomic replacement.

## Command details

- **Command type:** [`cmdlet`](/en/powershell/latest/reference/glossary/#cmdlet)
- **Default parameter set:** Server
- **Confirmation:** Supports `-WhatIf` and `-Confirm`; confirm impact: Medium.
- **Positional binding:** Enabled.
- **Pipeline inputs:** `LibTmux.Server`: A native server owner.; `LibTmux.Session`: A native session owner.; `LibTmux.Window`: A native window owner.; `LibTmux.Pane`: A native pane owner.
- **Outputs:** `LibTmux.TmuxHook`

Related APIs:

- [Hooks](https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/docs/hooks.md)

## Examples

Example 1

Store one indexed command on a native $session and inspect the grouped result.

[Source example](https://github.com/libtmux/libtmux-powershell/blob/b06c64f844f3173de66b187eaeaf3915814318c6/docs/reference/LibTmux/Set-TmuxHook.md).

```powershell
$command = 'display-message "build finished"'
$session |
    LibTmux\Set-TmuxHook -Name 'alert-bell[7]' -Command $command -PassThru
```

## Parameters

- `Pane` (`LibTmux.Pane`): The native pane whose table is used. (for `Pane`)
  Required. Position 0. Accepts pipeline input by value. [`ValidateNotNull()`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatenotnullattribute?view=powershellsdk-7.4.0).
- `Name` (`System.String`): The tmux hook name, optionally indexed for a specific entry. tmux expands formats in names.
  Required. Named parameter. Does not accept pipeline input. [`ValidateNotNullOrEmpty()`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatenotnulloremptyattribute?view=powershellsdk-7.4.0). [`ValidatePattern("\\A[^\\x00]*[^\\s\\x00][^\\x00]*\\z")`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatepatternattribute?view=powershellsdk-7.4.0).
- `Scope` (`System.Nullable[LibTmux.OptionScope]`): Override the owner scope with Server, Session, Window or Pane. Omission uses the native owner scope.
  Optional. Named parameter. Does not accept pipeline input. [`ValidateSet(["Server","Session","Window","Pane"])`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatesetattribute?view=powershellsdk-7.4.0).
- `Global` (`System.Management.Automation.SwitchParameter`): Use the global table for the selected scope. For global session defaults from a Server, specify Scope Session and Global.
  Optional. Named parameter. Switch parameter. Does not accept pipeline input.
- `Command` (`System.String`): The tmux command text to run when the hook fires. This is tmux command syntax, not a PowerShell script block. NUL is rejected.
  Required. Named parameter. Does not accept pipeline input. [`ValidateNotNull()`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatenotnullattribute?view=powershellsdk-7.4.0). [`ValidatePattern("^[^\\x00]*$")`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatepatternattribute?view=powershellsdk-7.4.0).
- `Append` (`System.Management.Automation.SwitchParameter`): Keep existing entries and let tmux choose a free index. This need not be after the highest existing index.
  Optional. Named parameter. Switch parameter. Does not accept pipeline input.
- `PassThru` (`System.Management.Automation.SwitchParameter`): Emit the native value read back after the mutation. Without this switch, emit no success output. Readback still occurs.
  Optional. Named parameter. Switch parameter. Does not accept pipeline input.
- `Verbose` (`System.Management.Automation.SwitchParameter`): Display verbose messages produced by this command.
  Optional. Named parameter. Switch parameter. Common parameter. Does not accept pipeline input. Aliases: `vb`.
- `Debug` (`System.Management.Automation.SwitchParameter`): Display debug messages produced by this command.
  Optional. Named parameter. Switch parameter. Common parameter. Does not accept pipeline input. Aliases: `db`.
- `ErrorAction` (`System.Management.Automation.ActionPreference`): Choose how this command responds to non-terminating errors.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `ea`.
- `WarningAction` (`System.Management.Automation.ActionPreference`): Choose how this command responds to warning messages.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `wa`.
- `InformationAction` (`System.Management.Automation.ActionPreference`): Choose how this command handles information messages.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `infa`.
- `ProgressAction` (`System.Management.Automation.ActionPreference`): Choose how this command handles progress updates.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `proga`.
- `ErrorVariable` (`System.String`): Store the command's error records in the named variable.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `ev`.
- `WarningVariable` (`System.String`): Store the command's warning records in the named variable.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `wv`.
- `InformationVariable` (`System.String`): Store the command's information records in the named variable.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `iv`.
- `OutVariable` (`System.String`): Save output in the named variable while passing it down the pipeline.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `ov`.
- `OutBuffer` (`System.Int32`): Buffer output before passing it to the next pipeline command.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `ob`.
- `PipelineVariable` (`System.String`): Make the most recent output object available through a named variable within the pipeline.
  Optional. Named parameter. Common parameter. Does not accept pipeline input. Aliases: `pv`.
- `WhatIf` (`System.Management.Automation.SwitchParameter`): Show the selected owner, scope and operation without contacting tmux.
  Optional. Named parameter. Switch parameter. Does not accept pipeline input. Aliases: `wi`.
- `Confirm` (`System.Management.Automation.SwitchParameter`): Ask for confirmation before changing the selected table.
  Optional. Named parameter. Switch parameter. Does not accept pipeline input. Aliases: `cf`.
- `Server` (`LibTmux.Server`): The native server whose table is used. (for `Server`)
  Required. Position 0. Accepts pipeline input by value. [`ValidateNotNull()`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatenotnullattribute?view=powershellsdk-7.4.0).
- `Session` (`LibTmux.Session`): The native session whose table is used. (for `Session`)
  Required. Position 0. Accepts pipeline input by value. [`ValidateNotNull()`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatenotnullattribute?view=powershellsdk-7.4.0).
- `Window` (`LibTmux.Window`): The native window whose table is used. (for `Window`)
  Required. Position 0. Accepts pipeline input by value. [`ValidateNotNull()`](https://learn.microsoft.com/dotnet/api/system.management.automation.validatenotnullattribute?view=powershellsdk-7.4.0).

## Returns

`LibTmux.TmuxHook`: The complete native grouped hook, only with PassThru.
