testsAndMisc/linux_configuration/features/setup_game_rec.sh
Krzysztof kuhy Rudnicki f86c5c331d
Some checks are pending
md-naming / markdown naming convention (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (mypy, mypy) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (pylint, pylint) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (rest, ) (push) Waiting to run
Pre-commit checks / pre-commit (${{ matrix.group }}) (shellcheck, shellcheck) (push) Waiting to run
Python tests / test (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
Shell tests / shell-tests (push) Waiting to run
Shell tests / lib-tests (push) Waiting to run
Shell tests / arch-tests (push) Waiting to run
Add game-rec auto recorder for Steam games
Records every Steam game from launch to exit with gpu-screen-recorder: a jeepney D-Bus watcher on app-steam-app* scopes (game-rec-auto user unit), a $mod+Shift+g hotkey and an i3blocks dot. Failure modes: a daemon-reload no longer ends a live recording (ActiveState is re-checked before removal); a hotkey start with no matching audio stream falls back to the guessed app name and retries without it if gsr rejects it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01WzxdWVxiT9Y4MhGeKGz9dX
2026-11-22 22:50:54 +01:00

71 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
# ============================================================================
# Install game-rec (gaming/game_rec.sh): pacman deps, the ~/.local/bin/game-rec
# symlink, the i3blocks indicator symlink, the $mod+Shift+g hotkey in the
# live i3 config, and the game-rec-auto user service (gaming/game_rec_watch.sh,
# enabled at login, restarted here; recordings live in their own scopes, so a
# restart never stops one). Idempotent. It never reloads i3 or restarts
# i3blocks (a game may be running): it prints what to run instead.
# ============================================================================
set -euo pipefail
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
readonly REPO_DIR="${SCRIPT_DIR%/*}"
readonly PACKAGES=(gpu-screen-recorder xdotool xorg-xrandr util-linux coreutils procps-ng
python-jeepney systemd)
# Single-quoted on purpose: i3 passes $HOME through to sh -c.
# shellcheck disable=SC2016
readonly HOTKEY='bindsym $mod+Shift+g exec --no-startup-id $HOME/.local/bin/game-rec toggle'
readonly I3_CONFIG="$HOME/.config/i3/config"
readonly UNIT=game-rec-auto.service
readonly UNIT_DIR="$HOME/.config/systemd/user"
install_packages() {
local pkg
local -a missing=()
for pkg in "${PACKAGES[@]}"; do
pacman -Q "$pkg" >/dev/null 2>&1 || missing+=("$pkg")
done
((${#missing[@]} == 0)) || sudo pacman -S --needed --noconfirm "${missing[@]}"
}
link() {
mkdir -p "${2%/*}"
ln -sfn "$1" "$2"
}
add_hotkey() {
if [[ ! -f $I3_CONFIG ]]; then
printf 'skip hotkey: %s not found\n' "$I3_CONFIG"
return 0
fi
grep -qF -- "$HOTKEY" "$I3_CONFIG" && return 0
printf '\n# game recorder (linux_configuration/gaming/game_rec.sh)\n%s\n' \
"$HOTKEY" >>"$I3_CONFIG"
}
install_unit() {
mkdir -p "$UNIT_DIR"
sed "s|@GAME_REC_DIR@|$REPO_DIR/gaming|" "$REPO_DIR/features/systemd/$UNIT" \
>"$UNIT_DIR/$UNIT"
systemctl --user daemon-reload
systemctl --user enable "$UNIT" >/dev/null
systemctl --user restart "$UNIT"
}
main() {
install_packages
chmod +x "$REPO_DIR/gaming/game_rec.sh" "$REPO_DIR/gaming/game_rec_watch.sh" \
"$REPO_DIR/i3blocks/game_rec.sh"
link "$REPO_DIR/gaming/game_rec.sh" "$HOME/.local/bin/game-rec"
link "$REPO_DIR/i3blocks/game_rec.sh" "$HOME/.config/i3blocks/game_rec.sh"
add_hotkey
install_unit
printf 'game-rec installed. To activate (not done here):\n'
printf ' i3-msg restart (re-reads the hotkey, restarts i3bar + i3blocks)\n'
}
main "$@"