1
1
Fork 0

toggle: refactor with proper flags

Signed-off-by: Myned <dev@bjork.tech>
This commit is contained in:
Myned 2024-09-11 18:26:51 -05:00
parent 661ee80da0
commit bddacf341c
Signed by: myned
GPG key ID: C7224454F7881A34

View file

@ -1,27 +1,58 @@
#! /usr/bin/env bash #! /usr/bin/env bash
# Toggle tagged window, launch if needed set -x
#?? toggle TAG WORKSPACE [COMMAND]
# TODO: Use proper flags
# TODO: Support floating groups
if (("$#" >= 3)); then # Toggle pinned window, launch if needed
# Launch if tag does not exist yet #?? toggle --type TYPE --expression EXPRESSION --workspace WORKSPACE [COMMAND]
if ! hyprctl -j clients | jq -r '.[].tags[]' | grep "$1"; then #!! Regex may need to be double-escaped
hyprctl dispatch exec -- "${@:3}" # https://jqlang.github.io/jq/manual/#regular-expressions
focus=false
while (("$#" > 0)); do
case "$1" in
-e | --expression)
shift
expression="$1"
;;
-f | --focus)
focus=true
;;
-t | --type)
shift
type="$1"
;;
-w | --workspace)
shift
workspace="$1"
;;
--)
shift
break
;;
esac
shift
done
command="${*}"
if [[ "$command" ]]; then
if ! hyprctl -j clients | jq -re "any(.[].$type | test(\"$expression\"); . == true)"; then
hyprctl dispatch exec -- "$command" # Launch window
exit exit
fi fi
fi fi
# Dispatchers do not currently support matching by tag, so select address current_workspace="$(hyprctl -j clients | jq -r "first(.[] | select(.$type | test(\"$expression\")).workspace.name)")"
window="address:$(hyprctl -j clients | jq -r "first(.[] | select(.tags[] | startswith(\"$1\")).address)")"
workspace="$(hyprctl -j clients | jq -r "first(.[] | select(.tags[] | startswith(\"$1\")).workspace.name)")" if [[ "$current_workspace" == "$workspace" ]]; then
hyprctl dispatch movetoworkspacesilent "0,$type:$expression" # Move to current workspace first, otherwise some windows freeze
hyprctl dispatch pin "$type:$expression" # Pin
if [[ "$workspace" == "$2" ]]; then if "$focus"; then
hyprctl dispatch pin "$window" # Pin hyprctl dispatch focuswindow "$type:$expression" # Focus
(("$#" >= 3)) && hyprctl dispatch focuswindow "$window" # Focus if third argument fi
else else
hyprctl dispatch pin "$window" # Unpin hyprctl dispatch pin "$type:$expression" # Unpin
hyprctl dispatch movetoworkspacesilent "$2,$window" hyprctl dispatch movetoworkspacesilent "$workspace,$type:$expression" # Move to workspace
fi fi