From e4ca98301b4cdc035ce7cc8209f6909967a8adb0 Mon Sep 17 00:00:00 2001 From: v-oleg <82014227+v-oleg@users.noreply.github.com> Date: Sun, 14 Sep 2025 14:58:08 -0500 Subject: [PATCH] Add focus or launch script (#925) * Add focus or launch script * Replace eval with exec * Use eval so it properly expands the variables * Apply to the apps where it makes most sense --------- Co-authored-by: David Heinemeier Hansson --- bin/omarchy-launch-or-focus | 16 ++++++++++++++++ bin/omarchy-launch-or-focus-webapp | 8 ++++++++ config/hypr/bindings.conf | 12 ++++++------ migrations/1757877852.sh | 10 ++++++++++ 4 files changed, 40 insertions(+), 6 deletions(-) create mode 100755 bin/omarchy-launch-or-focus create mode 100755 bin/omarchy-launch-or-focus-webapp create mode 100644 migrations/1757877852.sh diff --git a/bin/omarchy-launch-or-focus b/bin/omarchy-launch-or-focus new file mode 100755 index 0000000..af63f00 --- /dev/null +++ b/bin/omarchy-launch-or-focus @@ -0,0 +1,16 @@ +#!/bin/bash + +if (($# == 0)); then + echo "Usage: omarchy-launch-or-focus [window-pattern] [launch-command]" + exit 1 +fi + +WINDOW_PATTERN="$1" +LAUNCH_COMMAND="${2:-"uwsm app -- $WINDOW_PATTERN"}" +WINDOW_ADDRESS=$(hyprctl clients -j | jq -r --arg p "$WINDOW_PATTERN" '.[]|select((.class+" "+.title)|test($p;"i"))|.address' | head -n1) + +if [[ -n $WINDOW_ADDRESS ]]; then + hyprctl dispatch focuswindow "address:$WINDOW_ADDRESS" +else + eval exec $LAUNCH_COMMAND +fi diff --git a/bin/omarchy-launch-or-focus-webapp b/bin/omarchy-launch-or-focus-webapp new file mode 100755 index 0000000..4af7f27 --- /dev/null +++ b/bin/omarchy-launch-or-focus-webapp @@ -0,0 +1,8 @@ +#!/bin/bash + +if (($# == 0)); then + echo "Usage: omarchy-launch-or-focus-webapp [window-pattern] [url]" + exit 1 +fi + +exec omarchy-launch-or-focus $1 "omarchy-launch-webapp '$2'" diff --git a/config/hypr/bindings.conf b/config/hypr/bindings.conf index 753402d..dfb131a 100644 --- a/config/hypr/bindings.conf +++ b/config/hypr/bindings.conf @@ -6,12 +6,12 @@ bindd = SUPER, return, Terminal, exec, $terminal --working-directory="$(omarchy- bindd = SUPER, F, File manager, exec, uwsm app -- nautilus --new-window bindd = SUPER, B, Browser, exec, $browser bindd = SUPER SHIFT, B, Browser (private), exec, $browser --private -bindd = SUPER, M, Music, exec, uwsm app -- spotify +bindd = SUPER, M, Music, exec, omarchy-launch-or-focus spotify bindd = SUPER, N, Neovim, exec, $terminal -e nvim bindd = SUPER, T, Activity, exec, $terminal -e btop bindd = SUPER, D, Docker, exec, $terminal -e lazydocker -bindd = SUPER, G, Signal, exec, uwsm app -- signal-desktop -bindd = SUPER, O, Obsidian, exec, uwsm app -- obsidian -disable-gpu --enable-wayland-ime +bindd = SUPER, G, Signal, exec, omarchy-launch-or-focus signal "uwsm app -- signal-desktop" +bindd = SUPER, O, Obsidian, exec, omarchy-launch-or-focus obsidian "uwsm app -- obsidian -disable-gpu --enable-wayland-ime" bindd = SUPER, slash, Passwords, exec, uwsm app -- 1password # If your web app url contains #, type it as ## to prevent hyperland treat it as comments @@ -19,9 +19,9 @@ bindd = SUPER, A, ChatGPT, exec, omarchy-launch-webapp "https://chatgpt.com" bindd = SUPER SHIFT, A, Grok, exec, omarchy-launch-webapp "https://grok.com" bindd = SUPER, C, Calendar, exec, omarchy-launch-webapp "https://app.hey.com/calendar/weeks/" bindd = SUPER, E, Email, exec, omarchy-launch-webapp "https://app.hey.com" -bindd = SUPER, Y, YouTube, exec, omarchy-launch-webapp "https://youtube.com/" -bindd = SUPER SHIFT, G, WhatsApp, exec, omarchy-launch-webapp "https://web.whatsapp.com/" -bindd = SUPER ALT, G, Google Messages, exec, omarchy-launch-webapp "https://messages.google.com/web/conversations" +bindd = SUPER, Y, YouTube, exec, omarchy-launch-or-focus-webapp YouTube "https://youtube.com/" +bindd = SUPER SHIFT, G, WhatsApp, exec, omarchy-launch-or-focus-webapp WhatsApp "https://web.whatsapp.com/" +bindd = SUPER ALT, G, Google Messages, exec, omarchy-launch-or-focus-webapp "Google Messages" "https://messages.google.com/web/conversations" bindd = SUPER, X, X, exec, omarchy-launch-webapp "https://x.com/" bindd = SUPER SHIFT, X, X Post, exec, omarchy-launch-webapp "https://x.com/compose/post" diff --git a/migrations/1757877852.sh b/migrations/1757877852.sh new file mode 100644 index 0000000..a0b88bd --- /dev/null +++ b/migrations/1757877852.sh @@ -0,0 +1,10 @@ +echo "Switch select bindings to launch or focus mode" + +if [[ -f ~/.config/hypr/bindings.conf ]]; then + sed -i '/SUPER, M, Music, exec/ c\bindd = SUPER, M, Music, exec, omarchy-launch-or-focus spotify' ~/.config/hypr/bindings.conf + sed -i '/SUPER, O, Obsidian, exec/ c\bindd = SUPER, O, Obsidian, exec, omarchy-launch-or-focus obsidian "uwsm app -- obsidian -disable-gpu --enable-wayland-ime"' ~/.config/hypr/bindings.conf + + sed -i '/SUPER, G, Signal, exec/ c\bindd = SUPER, G, Signal, exec, omarchy-launch-or-focus signal "uwsm app -- signal-desktop"' ~/.config/hypr/bindings.conf + sed -i '/SUPER SHIFT, G, WhatsApp, exec/ c\bindd = SUPER SHIFT, G, WhatsApp, exec, omarchy-launch-or-focus-webapp WhatsApp "https://web.whatsapp.com/"' ~/.config/hypr/bindings.conf + sed -i '/SUPER ALT, G, Google Messages, exec/ c\bindd = SUPER ALT, G, Google Messages, exec, omarchy-launch-or-focus-webapp "Google Messages" "https://messages.google.com/web/conversations"' ~/.config/hypr/bindings.conf +fi