Created
April 10, 2025 03:24
-
-
Save mengwong/485cd70ea11f0d38129b535ddffc8886 to your computer and use it in GitHub Desktop.
Hyprland hotkey app switcher - shell script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Save as ~/.config/hypr/manage-workspace.sh | |
# Function to check if a window exists in Hyprland | |
is_window_open() { | |
case "$1" in | |
"firefox") | |
hyprctl clients | grep -q "class: firefox" > /dev/null | |
;; | |
"emacs") | |
hyprctl clients | grep -q "class: Emacs" > /dev/null | |
;; | |
"terminal1") | |
hyprctl clients | grep -q "title: Terminal 1" > /dev/null | |
;; | |
"terminal2") | |
hyprctl clients | grep -q "title: Terminal 2" > /dev/null | |
;; | |
"terminal3") | |
hyprctl clients | grep -q "title: Terminal 3" > /dev/null | |
;; | |
esac | |
return $? | |
} | |
# Function to launch or focus applications | |
launch_or_focus() { | |
if ! is_window_open "$1" > /dev/null; then | |
# Launch the application if not running | |
case "$1" in | |
"firefox") | |
firefox & | |
;; | |
"emacs") | |
emacs & | |
;; | |
"terminal1") | |
kitty --title "Terminal 1" & | |
;; | |
"terminal2") | |
kitty --title "Terminal 2" & | |
;; | |
"terminal3") | |
kitty --title "Terminal 3" & | |
;; | |
esac | |
# Wait for launch | |
sleep 0.5 | |
fi | |
# Focus the window | |
case "$1" in | |
"firefox") | |
hyprctl dispatch focuswindow "firefox" | |
;; | |
"emacs") | |
hyprctl dispatch focuswindow "Emacs" | |
;; | |
"terminal1") | |
hyprctl dispatch focuswindow "title:(Terminal 1)" | |
;; | |
"terminal2") | |
hyprctl dispatch focuswindow "title:(Terminal 2)" | |
;; | |
"terminal3") | |
hyprctl dispatch focuswindow "title:(Terminal 3)" | |
;; | |
esac | |
} | |
# If no argument, launch all applications and arrange them | |
if [ -z "$1" ]; then | |
launch_or_focus "terminal1" | |
# TODO figure out how to movewindows around to get the desired result | |
else | |
# Launch or focus specific application | |
launch_or_focus "$1" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment