Created
September 28, 2024 17:54
-
-
Save igorepst/fff009f6d1322bb0543e7185754ffa4a to your computer and use it in GitHub Desktop.
Run or raise for Hyprland
This file contains 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
#!/usr/bin/env sh | |
selectOne() { | |
target=$(hyprctl clients -j | jq -rc '.[] | select((.class |test("'"${1}"'")))') | |
if [ -n "${target}" ]; then | |
target=$(echo "${target}" | jq -r '.address') | |
hyprctl dispatch "focuswindow address:${target}" >/dev/null | |
return 0 | |
fi | |
return 1 | |
} | |
processFirst() { | |
set -f; IFS='|' | |
#shellcheck disable=SC2086 | |
set -- ${1} | |
for param in "$@"; do | |
if selectOne "${param}"; then | |
return 0; | |
fi | |
done | |
set +f; unset IFS | |
return 1 | |
} | |
doWork() { | |
if processFirst "$1"; then | |
true | |
elif [ -n "${2}" ]; then | |
shift | |
"$@" & | |
else | |
"${1}" & | |
fi | |
} | |
doWork "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment