|
| 1 | +# tmux Terraform Module |
| 2 | + |
| 3 | +This module provisions and configures [tmux](https://github.com/tmux/tmux) with session persistence and plugin support |
| 4 | +for a Coder agent. It automatically installs tmux, the Tmux Plugin Manager (TPM), and a set of useful plugins, and sets |
| 5 | +up a default or custom tmux configuration with session save/restore capabilities. |
| 6 | + |
| 7 | +## Features |
| 8 | + |
| 9 | +- Installs tmux if not already present |
| 10 | +- Installs TPM (Tmux Plugin Manager) |
| 11 | +- Configures tmux with plugins for sensible defaults, session persistence, and automation: |
| 12 | + - `tmux-plugins/tpm` |
| 13 | + - `tmux-plugins/tmux-sensible` |
| 14 | + - `tmux-plugins/tmux-resurrect` |
| 15 | + - `tmux-plugins/tmux-continuum` |
| 16 | +- Supports custom tmux configuration |
| 17 | +- Enables automatic session save/restore |
| 18 | +- Configurable save interval |
| 19 | + |
| 20 | +## Usage |
| 21 | + |
| 22 | +```hcl |
| 23 | +module "tmux" { |
| 24 | + source = "path/to/this/module" |
| 25 | + agent_id = coder_agent.example.id |
| 26 | + tmux_config = "" # Optional: custom tmux.conf content |
| 27 | + save_interval = 1 # Optional: save interval in minutes |
| 28 | +} |
| 29 | +``` |
| 30 | + |
| 31 | +## Input Variables |
| 32 | + |
| 33 | +| Name | Type | Description | Default | |
| 34 | +| ------------- | ------ | ----------------------------------- | ------- | |
| 35 | +| agent_id | string | The ID of a Coder agent. | n/a | |
| 36 | +| tmux_config | string | Custom tmux configuration to apply. | "" | |
| 37 | +| save_interval | number | Save interval (in minutes). | 1 | |
| 38 | + |
| 39 | +## How It Works |
| 40 | + |
| 41 | +- **tmux Installation:** |
| 42 | + - Checks if tmux is installed; if not, installs it using the system's package manager (supports apt, yum, dnf, |
| 43 | + zypper, apk, brew). |
| 44 | +- **TPM Installation:** |
| 45 | + - Installs the Tmux Plugin Manager (TPM) to `~/.tmux/plugins/tpm` if not already present. |
| 46 | +- **tmux Configuration:** |
| 47 | + - If `tmux_config` is provided, writes it to `~/.tmux.conf`. |
| 48 | + - Otherwise, generates a default configuration with plugin support and session persistence (using tmux-resurrect and |
| 49 | + tmux-continuum). |
| 50 | + - Sets up key bindings for quick session save (`Ctrl+s`) and restore (`Ctrl+r`). |
| 51 | +- **Plugin Installation:** |
| 52 | + - Installs plugins via TPM. |
| 53 | +- **Session Persistence:** |
| 54 | + - Enables automatic session save/restore at the configured interval. |
| 55 | + |
| 56 | +## Example |
| 57 | + |
| 58 | +```hcl |
| 59 | +module "tmux" { |
| 60 | + source = "./registry/anomaly/modules/tmux" |
| 61 | + agent_id = var.agent_id |
| 62 | + tmux_config = <<-EOT |
| 63 | + set -g mouse on |
| 64 | + set -g history-limit 10000 |
| 65 | + EOT |
| 66 | + save_interval = 2 |
| 67 | +} |
| 68 | +``` |
| 69 | + |
| 70 | +## Outputs |
| 71 | + |
| 72 | +This module does not export outputs. |
| 73 | + |
| 74 | +## Notes |
| 75 | + |
| 76 | +- If you provide a custom `tmux_config`, it will completely replace the default configuration. Ensure you include plugin |
| 77 | + and TPM initialization lines if you want plugin support. |
| 78 | +- The script will attempt to install dependencies using `sudo` where required. |
| 79 | +- If `git` is not installed, TPM installation will fail. |
| 80 | +- If you are using custom config, you'll be responsible for setting up persistence |
0 commit comments