#!/usr/bin/env bash set -euo pipefail SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)" CONFIG="$SCRIPT_DIR/workspace" declare -A TARGETS echo "Using config: $CONFIG" if [[ ! -f "$CONFIG" ]]; then echo "[ERROR] Config file not found!" exit 1 fi echo "[DEBUG] Config contents:" cat "$CONFIG" echo "[DEBUG] ---------------------" LINE_NUM=0 # ------------------------- # Launch applications # ------------------------- is_running() { local CLASS="$1" hyprctl clients -j | jq -e --arg class "$CLASS" \ '.[] | select(.class == $class)' >/dev/null } while IFS='|' read -r NAME CLASS COMMAND WORKSPACE; do [[ -z "${NAME:-}" ]] && continue [[ "$NAME" == "NAME" ]] && { echo "[DEBUG] Skipping header row" continue } echo "[DEBUG] Processing: $NAME ($CLASS)" if is_running "$CLASS"; then echo "[INFO] $NAME already running, skipping" else echo "[INFO] Launching $NAME" if pgrep -f "$COMMAND" >/dev/null 2>&1; then echo "[INFO] $NAME already running (pgrep match)" else if command -v "$COMMAND" >/dev/null 2>&1; then nohup "$COMMAND" >/dev/null 2>&1 & else echo "[WARN] '$COMMAND' not in PATH, trying desktop ID..." nohup gtk-launch "$CLASS" >/dev/null 2>&1 & fi fi fi TARGETS["$CLASS"]="$WORKSPACE" done < "$CONFIG" echo "[INFO] Waiting for windows..." declare -A DONE # ------------------------- # Wait + move windows # ------------------------- while true; do ALL_DONE=true for CLASS in "${!TARGETS[@]}"; do [[ -n "${DONE[$CLASS]:-}" ]] && continue WORKSPACE="${TARGETS[$CLASS]}" WIN=$(hyprctl clients -j | jq -r --arg class "$CLASS" \ '.[] | select(.class == $class) | .address' | head -n1) if [[ -z "$WIN" ]]; then echo "[DEBUG] Waiting for window class: $CLASS" ALL_DONE=false continue fi echo "[INFO] Found $CLASS -> $WIN (workspace $WORKSPACE)" hyprctl dispatch "hl.dsp.window.move({workspace = \"$WORKSPACE\", follow = false, window = \"address:$WIN\"})" # echo "hyprctl dispatch 'hl.dsp.window.move({workspace = \"$WORKSPACE\", follow = false, window = \"address:$WIN\"})'" # hyprctl dispatch movetoworkspacesilent "$WORKSPACE,address:$WIN" DONE["$CLASS"]=1 done if $ALL_DONE; then echo "[INFO] All windows moved." break fi sleep 0.5 done for i in 4 3 2 1; do echo "hyprctl dispatch \"hl.dsp.focus({workspace = \"$i\"})\"" hyprctl dispatch "hl.dsp.focus({workspace = \"$i\"})" echo "hyprctl dispatch workspace \"$i\"" hyprctl dispatch workspace "$i" if [ "$i" -eq 3 ]; then sleep 0.5 echo "R" wtype "R" sleep 0.5 fi done tmux new-session -d -s qs 'sleep 4 && quickshell'