From 239d74dfecf302b01f45652a2a78d69260cb88f9 Mon Sep 17 00:00:00 2001 From: FURK4NGG <105324908+FURK4NGG@users.noreply.github.com> Date: Tue, 20 Jan 2026 01:38:11 +0300 Subject: [PATCH] Update generate-waybar-configs.sh --- generate-waybar-configs.sh | 62 +++++++++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 11 deletions(-) diff --git a/generate-waybar-configs.sh b/generate-waybar-configs.sh index ebc177e..1aa5d55 100644 --- a/generate-waybar-configs.sh +++ b/generate-waybar-configs.sh @@ -4,26 +4,66 @@ set -e WAYBAR_DIR="$HOME/.config/waybar" BASE_CONFIG="$WAYBAR_DIR/config" -if [ ! -f "$BASE_CONFIG" ]; then - echo "[error] base config not found" - exit 1 -fi +command -v hyprctl >/dev/null || { echo "[error] hyprctl not found"; exit 1; } +command -v jq >/dev/null || { echo "[error] jq not found"; exit 1; } -command -v hyprctl >/dev/null || { - echo "[error] hyprctl not found" - exit 1 -} +cd "$WAYBAR_DIR" +# ----------------------------- +# 1) MONITORLER +# ----------------------------- MONITORS=$(hyprctl -j monitors | jq -r '.[].name') +[ -z "$MONITORS" ] && { + echo "[info] no monitors found, skipping" + exit 0 +} + +# ----------------------------- +# 2) BASE CONFIG BELLEĞE AL +# (output temizlenmiş halde) +# ----------------------------- +BASE_CONTENT="" + +strip_output() { + sed \ + -e 's/"output"[[:space:]]*:[[:space:]]*\[[^]]*\],[[:space:]]*//' \ + -e '1s/^{//' \ + "$1" +} + +if [ -f "$BASE_CONFIG" ]; then + echo "[info] base config: config" + BASE_CONTENT="$(strip_output "$BASE_CONFIG")" +else + FIRST_MONITOR_CONFIG=$(ls config-* 2>/dev/null | head -n 1 || true) + + [ -z "$FIRST_MONITOR_CONFIG" ] && { + echo "[error] no base config found" + exit 1 + } + + echo "[info] base config: $FIRST_MONITOR_CONFIG" + BASE_CONTENT="$(strip_output "$FIRST_MONITOR_CONFIG")" +fi + +# ----------------------------- +# 3) TEMİZLİK (MONITOR VARSA) +# ----------------------------- +rm -f config +rm -f config-* + +# ----------------------------- +# 4) YENİ CONFIGLER +# ----------------------------- for MONITOR in $MONITORS; do - TARGET="$WAYBAR_DIR/config-$MONITOR" + TARGET="config-$MONITOR" { echo '{' echo " \"output\": [\"$MONITOR\"]," - sed '1s/^{//' "$BASE_CONFIG" + echo "$BASE_CONTENT" } > "$TARGET" - echo "[ok] generated $TARGET for $MONITOR" + echo "[ok] generated $TARGET" done