Files
omarchycn/bin/omarchy-restart-shell
T
David Heinemeier HanssonandClaude Fable 5 afcbcc0e36 Replace shell instances with quickshell's synchronous kill
With quickshell-git, qs kill blocks until the instance has fully
exited, so restarting no longer needs to resolve pids and wait for them
to die. Kill in a loop until none remain - each call takes the oldest,
and duplicates from stale sessions are the reason this script exists.
The timeout bounds a wedged shell that can't process the quit message:
its kill would otherwise report success after Qt's 30s wait gives up,
re-killing the same undead instance forever. The test mock now kills
real processes synchronously to match.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-21 15:27:12 -07:00

35 lines
1.4 KiB
Bash
Executable File

#!/bin/bash
# omarchy:summary=Restart the Omarchy shell
# omarchy:examples=omarchy restart shell
CONFIG_DIR="$OMARCHY_PATH/shell"
[[ -f $CONFIG_DIR/shell.qml ]] || { echo "Omarchy shell config not found: $CONFIG_DIR" >&2; exit 1; }
# Allow running from outside the session (e.g. over ssh) by deriving the
# Hyprland instance signature from the newest instance runtime dir.
if [[ -z ${HYPRLAND_INSTANCE_SIGNATURE:-} ]]; then
hypr_dir=$(find "${XDG_RUNTIME_DIR:-/run/user/$UID}/hypr" -mindepth 1 -maxdepth 1 -type d -printf '%T@ %p\n' 2>/dev/null | sort -n | tail -n 1 | cut -d' ' -f2-)
[[ -n $hypr_dir ]] && export HYPRLAND_INSTANCE_SIGNATURE=${hypr_dir##*/}
fi
if [[ $(hyprctl -j monitors 2>/dev/null) == *'"LOCK"'* ]]; then
echo "Refusing to restart Omarchy shell while the session is locked." >&2
exit 1
fi
# Each kill stops the oldest matching instance and only returns once it has
# fully exited, so the no-duplicate launch below can't race a dying shell.
# Requires our quickshell-git build; 0.3.0's kill returns immediately.
while timeout 5 quickshell kill -p "$CONFIG_DIR" --any-display >/dev/null 2>&1; do :; done
setsid quickshell -n -p "$CONFIG_DIR" >/dev/null 2>&1 &
for (( attempt = 0; attempt < 20; attempt++ )); do
OMARCHY_SHELL_IPC_TIMEOUT=0.5s omarchy-shell shell ping >/dev/null 2>&1 && exit 0
sleep 0.1
done
echo "Omarchy shell did not become ready after restart." >&2
exit 1