Drop vestigial env reconstruction from shell restart
The /proc/*/environ scraping, wayland/X11 socket probing, and LANG/DBUS guessing arrived with the Omarchy 4 live upgrade cutover, whose upgrade script no longer exists. Every remaining caller runs inside the graphical session with full env. Keep a five-line guard deriving HYPRLAND_INSTANCE_SIGNATURE from the newest instance runtime dir so restarting over ssh still works. Launching now goes straight to the Lua dispatcher: on quattro, classic hyprctl dispatch arguments are evaluated as Lua and fail with exit 0, so the old exec fallback silently did nothing. Check for "ok" output instead of trusting the exit code, with setsid as the real fallback. 180 lines to 94. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
4a2502cb63
commit
cacd22c671
+10
-96
@@ -17,91 +17,12 @@ export PATH="$omarchy_root/bin:/usr/local/bin:/usr/bin:/bin:$PATH"
|
|||||||
omarchy_shell_bin=/usr/bin/omarchy-shell
|
omarchy_shell_bin=/usr/bin/omarchy-shell
|
||||||
[[ -x $omarchy_shell_bin ]] || omarchy_shell_bin=omarchy-shell
|
[[ -x $omarchy_shell_bin ]] || omarchy_shell_bin=omarchy-shell
|
||||||
|
|
||||||
import_env_from_pid() {
|
# Allow running from outside the session (e.g. over ssh) by deriving the
|
||||||
local pid=$1 entry key
|
# Hyprland instance signature from the newest instance runtime dir.
|
||||||
|
if [[ -z ${HYPRLAND_INSTANCE_SIGNATURE:-} ]]; then
|
||||||
[[ -r /proc/$pid/environ ]] || return 1
|
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##*/}
|
||||||
while IFS= read -r -d '' entry; do
|
fi
|
||||||
key=${entry%%=*}
|
|
||||||
case $key in
|
|
||||||
DBUS_SESSION_BUS_ADDRESS | DISPLAY | HYPRLAND_INSTANCE_SIGNATURE | LANG | LC_ALL | LC_CTYPE | QT_QPA_PLATFORM | WAYLAND_DISPLAY | XDG_CURRENT_DESKTOP | XDG_RUNTIME_DIR | XDG_SESSION_TYPE)
|
|
||||||
[[ -n ${!key:-} ]] || export "$entry"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done <"/proc/$pid/environ"
|
|
||||||
}
|
|
||||||
|
|
||||||
import_graphical_session_env() {
|
|
||||||
local current_user hypr_dir pid wayland_socket x11_socket
|
|
||||||
|
|
||||||
current_user=${USER:-$(id -un)}
|
|
||||||
|
|
||||||
for pid in $(pgrep -xu "$current_user" quickshell 2>/dev/null || true); do
|
|
||||||
import_env_from_pid "$pid" || true
|
|
||||||
done
|
|
||||||
|
|
||||||
for pid in $(pgrep -u "$UID" -f '/omarchy-hyprland-monitor-watch($| )' 2>/dev/null || true); do
|
|
||||||
import_env_from_pid "$pid" || true
|
|
||||||
done
|
|
||||||
|
|
||||||
if [[ -z ${XDG_RUNTIME_DIR:-} && -d /run/user/$UID ]]; then
|
|
||||||
export XDG_RUNTIME_DIR="/run/user/$UID"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -z ${WAYLAND_DISPLAY:-} && -n ${XDG_RUNTIME_DIR:-} ]]; then
|
|
||||||
for wayland_socket in "$XDG_RUNTIME_DIR"/wayland-*; do
|
|
||||||
[[ -S $wayland_socket ]] || continue
|
|
||||||
export WAYLAND_DISPLAY=${wayland_socket##*/}
|
|
||||||
break
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -z ${DISPLAY:-} ]]; then
|
|
||||||
for x11_socket in /tmp/.X11-unix/X*; do
|
|
||||||
[[ -S $x11_socket ]] || continue
|
|
||||||
export DISPLAY=:${x11_socket##*X}
|
|
||||||
break
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -z ${HYPRLAND_INSTANCE_SIGNATURE:-} && -n ${XDG_RUNTIME_DIR:-} && -d $XDG_RUNTIME_DIR/hypr ]]; then
|
|
||||||
hypr_dir=$(find "$XDG_RUNTIME_DIR/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 [[ -z ${LANG:-} || $LANG == "C" || $LANG == "POSIX" ]]; then
|
|
||||||
if locale -a 2>/dev/null | grep -qxF "C.utf8"; then
|
|
||||||
export LANG="C.utf8"
|
|
||||||
else
|
|
||||||
export LANG="C.UTF-8"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -z ${QT_QPA_PLATFORM:-} ]]; then
|
|
||||||
export QT_QPA_PLATFORM="wayland;xcb"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ -z ${DBUS_SESSION_BUS_ADDRESS:-} && -n ${XDG_RUNTIME_DIR:-} && -S $XDG_RUNTIME_DIR/bus ]]; then
|
|
||||||
export DBUS_SESSION_BUS_ADDRESS="unix:path=$XDG_RUNTIME_DIR/bus"
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
require_graphical_session_env() {
|
|
||||||
local missing=()
|
|
||||||
|
|
||||||
[[ -n ${XDG_RUNTIME_DIR:-} ]] || missing+=(XDG_RUNTIME_DIR)
|
|
||||||
[[ -n ${WAYLAND_DISPLAY:-} || -n ${DISPLAY:-} ]] || missing+=(WAYLAND_DISPLAY)
|
|
||||||
|
|
||||||
if [[ -n ${XDG_RUNTIME_DIR:-} && -d $XDG_RUNTIME_DIR/hypr && -z ${HYPRLAND_INSTANCE_SIGNATURE:-} ]]; then
|
|
||||||
missing+=(HYPRLAND_INSTANCE_SIGNATURE)
|
|
||||||
fi
|
|
||||||
|
|
||||||
if (( ${#missing[@]} > 0 )); then
|
|
||||||
printf 'Refusing to restart Omarchy shell; missing graphical session environment: %s\n' "${missing[*]}" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
hyprland_session_locked() {
|
hyprland_session_locked() {
|
||||||
local monitors
|
local monitors
|
||||||
@@ -133,14 +54,10 @@ launch_shell() {
|
|||||||
|
|
||||||
launch_command="env OMARCHY_PATH=$(shell_quote "$omarchy_root") PATH=$(shell_quote "$PATH") quickshell -n -p $(shell_quote "$CONFIG_DIR")"
|
launch_command="env OMARCHY_PATH=$(shell_quote "$omarchy_root") PATH=$(shell_quote "$PATH") quickshell -n -p $(shell_quote "$CONFIG_DIR")"
|
||||||
|
|
||||||
if [[ -n ${HYPRLAND_INSTANCE_SIGNATURE:-} ]] && omarchy-cmd-present hyprctl; then
|
# hyprctl dispatch exits 0 even on Lua errors, so check for "ok" output.
|
||||||
if hyprctl dispatch "hl.dsp.exec_cmd($(lua_quote "$launch_command"))" >/dev/null 2>&1; then
|
if [[ -n ${HYPRLAND_INSTANCE_SIGNATURE:-} ]] && omarchy-cmd-present hyprctl &&
|
||||||
return 0
|
[[ $(hyprctl dispatch "hl.dsp.exec_cmd($(lua_quote "$launch_command"))" 2>/dev/null) == ok ]]; then
|
||||||
fi
|
return 0
|
||||||
|
|
||||||
if hyprctl dispatch exec "$launch_command" >/dev/null 2>&1; then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
setsid quickshell -n -p "$CONFIG_DIR" >/dev/null 2>&1 &
|
setsid quickshell -n -p "$CONFIG_DIR" >/dev/null 2>&1 &
|
||||||
@@ -160,9 +77,6 @@ restore_hyprland_session_lock() {
|
|||||||
echo "Omarchy shell restarted while Hyprland was session-locked, but lock IPC did not become ready." >&2
|
echo "Omarchy shell restarted while Hyprland was session-locked, but lock IPC did not become ready." >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
import_graphical_session_env
|
|
||||||
require_graphical_session_env
|
|
||||||
|
|
||||||
hyprland_was_session_locked=0
|
hyprland_was_session_locked=0
|
||||||
hyprland_session_locked && hyprland_was_session_locked=1
|
hyprland_session_locked && hyprland_was_session_locked=1
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user