mirror of
https://github.com/omacom/omarchy.git
synced 2026-09-28 06:13:13 +08:00
Trim launcher overhead for terminals and web apps (#13423)
omarchy-launch-webapp asked xdg-settings for the default browser with BROWSER still set to omarchy-launch-browser, which sends it down a slower path to the same answer: ~105ms instead of ~30ms on every web app launch. Unset it, as omarchy-launch-browser already does. omarchy-cmd-terminal-cwd found the focused terminal's shell with pgrep, which scans all of /proc on every new terminal. Read the terminal's child lists from /proc instead, keeping the newest child as before. Web app wrapper overhead drops from ~111ms to ~34ms, and a new terminal appears in ~77ms instead of ~90ms. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
804749970a
commit
25ead28f90
@@ -11,7 +11,16 @@ if [[ -S $kitty_socket ]]; then
|
||||
cwd=$(kitten @ --to "unix:$kitty_socket" ls --match "state:focused" 2>/dev/null |
|
||||
jq -r '.[].tabs[].windows[].cwd // empty')
|
||||
else
|
||||
shell_pid=$(pgrep -P "$terminal_pid" | tail -n1)
|
||||
# The newest child, as pgrep -P | tail -n1 found it, read from the kernel's
|
||||
# child lists: pgrep scans all of /proc on every new terminal.
|
||||
shell_pid=""
|
||||
for children_file in /proc/"$terminal_pid"/task/*/children; do
|
||||
[[ -r $children_file ]] || continue
|
||||
read -ra children <"$children_file" || true
|
||||
for child in "${children[@]}"; do
|
||||
(( child > ${shell_pid:-0} )) && shell_pid=$child
|
||||
done
|
||||
done
|
||||
|
||||
if [[ -n $shell_pid ]]; then
|
||||
cwd=$(readlink -f "/proc/$shell_pid/cwd" 2>/dev/null)
|
||||
|
||||
@@ -3,7 +3,9 @@
|
||||
# omarchy:summary=Launch a URL as a web app in the default supported browser
|
||||
# omarchy:args=<url>
|
||||
|
||||
browser=$(xdg-settings get default-web-browser)
|
||||
# The session sets BROWSER to omarchy-launch-browser, which sends xdg-settings
|
||||
# down a slower path (~100ms against ~30ms) to the same answer.
|
||||
browser=$(env -u BROWSER xdg-settings get default-web-browser)
|
||||
|
||||
case $browser in
|
||||
google-chrome* | brave* | microsoft-edge* | opera* | vivaldi* | helium*) ;;
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"
|
||||
|
||||
test_tmp=$(mktemp -d)
|
||||
stub_bin="$test_tmp/bin"
|
||||
work_dir="$test_tmp/project dir"
|
||||
mkdir -p "$stub_bin" "$work_dir"
|
||||
|
||||
# A stand-in terminal whose newest child is a shell sitting in work_dir. The
|
||||
# trailing ":" keeps bash from exec'ing sleep, so the child stays a shell.
|
||||
bash -c '(cd "$1" && bash -c "sleep 30; :") & wait' _ "$work_dir" &
|
||||
terminal_pid=$!
|
||||
|
||||
# Children first: killing a parent reparents its children out of reach.
|
||||
kill_tree() {
|
||||
local child
|
||||
for child in $(cat /proc/"$1"/task/*/children 2>/dev/null); do
|
||||
kill_tree "$child"
|
||||
done
|
||||
kill "$1" 2>/dev/null || true
|
||||
}
|
||||
trap 'kill_tree "$terminal_pid"; wait "$terminal_pid" 2>/dev/null || true; rm -rf "$test_tmp"' EXIT
|
||||
|
||||
for _ in $(seq 50); do
|
||||
[[ -n $(cat /proc/"$terminal_pid"/task/*/children 2>/dev/null) ]] && break
|
||||
sleep 0.05
|
||||
done
|
||||
|
||||
cat >"$stub_bin/hyprctl" <<'SH'
|
||||
#!/bin/bash
|
||||
[[ -n ${ACTIVE_PID:-} ]] && printf 'Window 1 -> terminal:\n\tpid: %s\n' "$ACTIVE_PID"
|
||||
exit 0
|
||||
SH
|
||||
chmod +x "$stub_bin/hyprctl"
|
||||
|
||||
cwd=$(ACTIVE_PID="$terminal_pid" PATH="$stub_bin:$PATH" XDG_RUNTIME_DIR="$test_tmp" "$ROOT/bin/omarchy-cmd-terminal-cwd")
|
||||
[[ $cwd == "$work_dir" ]] || fail "a new terminal opens in the focused terminal's shell directory" "got: $cwd"
|
||||
pass "a new terminal opens in the focused terminal's shell directory"
|
||||
|
||||
output=$(PATH="$stub_bin:$PATH" XDG_RUNTIME_DIR="$test_tmp" HOME="$test_tmp" "$ROOT/bin/omarchy-cmd-terminal-cwd" 2>&1)
|
||||
[[ $output == "$test_tmp" ]] || fail "with no focused terminal the new one opens in HOME" "got: $output"
|
||||
pass "with no focused terminal the new one opens in HOME, quietly"
|
||||
Reference in New Issue
Block a user