Files
claude-foundations/hooks/set-wezterm-profile.sh
Paul O'Reilly c3557a3d97 Add formatters, hooks, memory entries and context-load improvements
- formatters/js, md, yaml: new/updated formatter scripts
- hooks/set-wezterm-profile.sh: new hook for WezTerm profile switching
- scripts/context-load: improvements from recent sessions
- HOOKS.md, MEMORY.md: updated documentation and index entries
- memory/log, memory/reference-infrastructure-docs.md: session logs and reference

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-03-19 10:54:49 +13:00

45 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# set-wezterm-profile.sh — SessionStart hook: emit WezTerm theme escape sequence
#
# Derives the profile name from CLAUDE_CONFIG_DIR (e.g. ~/.claude-octopus → octopus)
# and emits a SetUserVar escape sequence so WezTerm fires its user-var-changed
# event and applies the matching theme from wezterm.lua.
#
# Hook subprocesses have no controlling terminal, so the escape sequence is
# written to the pts device found by walking up the process tree.
# Safe in non-WezTerm terminals (escape sequence is silently ignored).
#
# Usage (settings.json):
# "SessionStart": [{ "hooks": [{ "type": "command",
# "command": "~/.claude/hooks/set-wezterm-profile.sh" }] }]
set -euo pipefail
profile_dir="${CLAUDE_CONFIG_DIR:-$HOME/.claude}"
profile_name="${profile_dir##*/.claude-}"
# No profile suffix means this is the default profile — nothing to do
if [[ "$profile_name" == "$profile_dir" ]]; then
exit 0
fi
# Emit the escape sequence to the terminal device.
# Hook subprocesses have no controlling terminal (/dev/tty unavailable),
# so walk up the process tree to find the first ancestor with a pts device.
tty_device=""
pid=$$
while [[ "$pid" -gt 1 ]]; do
pts=$(ps -o tty= -p "$pid" 2>/dev/null | tr -d ' ')
if [[ -n "$pts" && "$pts" != "?" && -w "/dev/$pts" ]]; then
tty_device="/dev/$pts"
break
fi
pid=$(ps -o ppid= -p "$pid" 2>/dev/null | tr -d ' ')
done
if [[ -n "$tty_device" ]]; then
printf '\e]1337;SetUserVar=%s=%s\a' CLAUDE_PROFILE \
"$(printf '%s' "$profile_name" | base64)" >"$tty_device" 2>/dev/null || true
fi