Files
hypr/scripts/autostart/autostart.sh
T
2026-06-14 18:49:46 +02:00

108 lines
2.5 KiB
Bash
Executable File

#!/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 movetoworkspacesilent "$WORKSPACE,address:$WIN"
DONE["$CLASS"]=1
done
if $ALL_DONE; then
echo "[INFO] All windows moved."
break
fi
sleep 0.5
done
hyprctl dispatch workspace 4
hyprctl dispatch workspace 3
hyprctl dispatch workspace 2
hyprctl dispatch workspace 1
tmux new-session -d -s qs 'sleep 4 && quickshell'