mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-14 06:12:34 +00:00
35 lines
856 B
Bash
Executable File
35 lines
856 B
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
# Launch a web app or focus if it's already open.
|
|
|
|
if [[ $# == 0 ]]; then
|
|
echo "Usage: launch-or-focus-webapp <url>"
|
|
exit 1
|
|
fi
|
|
|
|
SCRIPTS="${SCRIPTS}"
|
|
|
|
if [[ -z $SCRIPTS ]]; then
|
|
echo "scripts directory not set"
|
|
echo "using ~/.local/scripts"
|
|
SCRIPTS=~/.local/scripts
|
|
fi
|
|
|
|
url=$1
|
|
|
|
# parse domain pattern from the url
|
|
pattern=${url#https:\/\/} # removing leading 'https://'
|
|
pattern=${pattern#http:\/\/} # removing leading 'http://'
|
|
pattern=${pattern%%/*} # removing everything after '/' that's left (which should leave us with the domain)
|
|
|
|
window=$(hyprctl clients -j | jq -r ".[] | select((.class | contains(\"$pattern\"))) | .address")
|
|
|
|
echo "Pattern: \"$pattern\""
|
|
echo "Window: \"$window\""
|
|
|
|
if [[ -n $window ]]; then
|
|
hyprctl dispatch focuswindow "address:$window"
|
|
else
|
|
eval exec "$SCRIPTS/launch-webapp $url"
|
|
fi
|