mirror of
https://github.com/js0ny/dotfiles.git
synced 2026-03-22 10:42:42 +00:00
22 lines
768 B
Nix
22 lines
768 B
Nix
{pkgs, ...}: {
|
|
launch-or-focus = pkgs.writeShellApplication {
|
|
name = "hyprscript-launch-or-focus";
|
|
runtimeInputs = [pkgs.jq pkgs.hyprland pkgs.uwsm];
|
|
text = ''
|
|
if (($# == 0)); then
|
|
echo "Usage: hyprscript-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|test("\\b" + $p + "\\b";"i")) or (.title|test("\\b" + $p + "\\b";"i")))|.address' | head -n1)
|
|
|
|
if [[ -n $WINDOW_ADDRESS ]]; then
|
|
hyprctl dispatch focuswindow "address:$WINDOW_ADDRESS"
|
|
else
|
|
eval exec setsid "$LAUNCH_COMMAND"
|
|
fi
|
|
'';
|
|
};
|
|
}
|