Refactor of the hypr config
This commit is contained in:
Executable
+101
@@ -0,0 +1,101 @@
|
||||
#!/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
|
||||
Reference in New Issue
Block a user