From c02a4669a923c8ecdfd0bbca75823be2b6c4c5d5 Mon Sep 17 00:00:00 2001 From: Nick Ludwig Date: Fri, 11 Sep 2026 14:56:27 -0700 Subject: [PATCH] when the file explorer is focused, opening a new one opens to the same dir --- bin/omarchy-launch-nautilus | 12 +++++-- test/shell.d/launch-nautilus-test.sh | 52 ++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) create mode 100755 test/shell.d/launch-nautilus-test.sh diff --git a/bin/omarchy-launch-nautilus b/bin/omarchy-launch-nautilus index 0b10b7b2a83..5afdfc34c42 100755 --- a/bin/omarchy-launch-nautilus +++ b/bin/omarchy-launch-nautilus @@ -1,5 +1,13 @@ #!/bin/bash -# omarchy:summary=Launch Files +# omarchy:summary=Launch Files, reusing the current folder when Files is focused -exec setsid uwsm-app -- nautilus --new-window +# Use the same action as Ctrl+N so Nautilus resolves the active window and tab. +if [[ $(hyprctl activewindow -j 2>/dev/null | jq -r '.class') == "org.gnome.Nautilus" ]] && + gdbus call --session --dest org.gnome.Nautilus \ + --object-path /org/gnome/Nautilus --method org.gtk.Actions.Activate \ + --timeout 5 clone-window '[]' '{}' >/dev/null 2>&1; then + exit 0 +else + exec setsid uwsm-app -- nautilus --new-window +fi diff --git a/test/shell.d/launch-nautilus-test.sh b/test/shell.d/launch-nautilus-test.sh new file mode 100755 index 00000000000..3647fb501a6 --- /dev/null +++ b/test/shell.d/launch-nautilus-test.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +set -euo pipefail + +source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" + +scratch=$(mktemp -d) +trap 'rm -rf "$scratch"' EXIT +mkdir -p "$scratch/bin" +export CALL_LOG="$scratch/calls" + +cat > "$scratch/bin/hyprctl" <<'SH' +#!/bin/bash +printf '%s\n' "$ACTIVE_WINDOW" +SH + +cat > "$scratch/bin/gdbus" <<'SH' +#!/bin/bash +printf 'gdbus %s\n' "$*" >> "$CALL_LOG" +exit "${DBUS_STATUS:-0}" +SH + +cat > "$scratch/bin/setsid" <<'SH' +#!/bin/bash +printf 'launch %s\n' "$*" >> "$CALL_LOG" +SH +chmod +x "$scratch/bin/"* +export PATH="$scratch/bin:$PATH" + +run_launcher() { + : > "$CALL_LOG" + bash "$ROOT/bin/omarchy-launch-nautilus" +} + +export ACTIVE_WINDOW='{"class":"org.gnome.Nautilus"}' +run_launcher +[[ $(cat "$CALL_LOG") == 'gdbus call --session --dest org.gnome.Nautilus --object-path /org/gnome/Nautilus --method org.gtk.Actions.Activate --timeout 5 clone-window [] {}' ]] || + fail "focused Files clones the active window without launching Home" +pass "focused Files clones the active window without launching Home" + +for ACTIVE_WINDOW in '{"class":"foot"}' '{}' '{"class":"org.gnome.NautilusPreviewer"}' ''; do + run_launcher + [[ $(cat "$CALL_LOG") == 'launch uwsm-app -- nautilus --new-window' ]] || + fail "a fresh Files window opens when Files is not focused" "$ACTIVE_WINDOW" +done +pass "a fresh Files window opens when Files is not focused or no window is available" + +export ACTIVE_WINDOW='{"class":"org.gnome.Nautilus"}' DBUS_STATUS=1 +run_launcher +[[ $(tail -n 1 "$CALL_LOG") == 'launch uwsm-app -- nautilus --new-window' ]] || + fail "a failed clone request falls back to opening Files" +pass "a failed clone request falls back to opening Files"