Run configured commands in detached tmux sessions
- Python 88.4%
- Nix 11.6%
| .gitignore | ||
| example_config.yaml | ||
| flake.lock | ||
| flake.nix | ||
| LICENSE | ||
| pyproject.toml | ||
| README.org | ||
| sessions.py | ||
sessions
sessions runs configured commands in detached tmux sessions.
$ sessions list hytale ● running hytale-map ● idle luanti ● running backup ● error (exit 2) dev-server ○ stopped $ sessions restart hytale dev hytale ● running dev-server ● running was not running
Usage
usage: sessions [-h] [--sessions-config SESSIONS_CONFIG] {ls,list,start,restart,stop} [sessions ...]
Run configured commands in detached tmux sessions.
positional arguments:
{ls,list,start,restart,stop}
Sessions command
sessions Session names or prefixes (default: all configured)
options:
-h, --help show this help message and exit
--sessions-config, -c SESSIONS_CONFIG
Path to sessions config (default ~/.config/sessions.yaml)
Each sessions argument selects the session with exactly this name, or all sessions starting with it if none matches exactly.
Commands
| Command | Description |
|---|---|
ls / list |
Shows all configured sessions and their current state |
start |
Creates missing sessions and restarts idle or failed ones |
stop |
Sends SIGTERM, waits up to 30s, then sends SIGKILL |
restart |
First stop, then start |
Sessions can be observed via tmux:
tmux attach -t <session_name>to attach to a running sessionCtrl-b dto detach from a running session
States
| State | Description |
|---|---|
running |
Command is running |
idle |
Command finished with exit code 0 |
error |
Command failed with an exit code or was killed by a signal |
stopped |
No tmux session exists |
unmanaged |
Session wasn't created by sessions, start and stop skip it |
Installation
Requirements
tmuxPython3.11 or newer (only without Nix)
Nix
Try without installing:
nix shell github:Deleh/sessions
Add it to your profile:
nix profile add github:Deleh/sessions
Install on NixOS managed with flakes:
inputs.sessions.url = "github:Deleh/sessions";
# ...
environment.systemPackages = [
inputs.sessions.packages.${pkgs.stdenv.hostPlatform.system}.default
];
Without Nix
uv tool install git+https://github.com/Deleh/sessions
# or
pipx install git+https://github.com/Deleh/sessions
Config
The following snippet shows two configured sessions:
hytale:
directory: "~/games/hytale"
command: "./start-server.sh"
backup:
command: "restic backup ~/documents"
Notes:
- Each top-level key defines a session
- The
commandis mandatory - The
directoryis optional ~and$VARSare expanded in thedirectory- Session names can't contain
.or: - If a session name appears twice, the last one wins
An example config file with some edge cases for testing can be found in /denis/sessions/src/branch/main/example_config.yaml.
The default config path is ~/.config/sessions.yaml.
Credits
sessions is basically a simple wrapper around libtmux.