Update generate-waybar-configs.sh
This commit is contained in:
+50
-10
@@ -4,26 +4,66 @@ set -e
|
|||||||
WAYBAR_DIR="$HOME/.config/waybar"
|
WAYBAR_DIR="$HOME/.config/waybar"
|
||||||
BASE_CONFIG="$WAYBAR_DIR/config"
|
BASE_CONFIG="$WAYBAR_DIR/config"
|
||||||
|
|
||||||
if [ ! -f "$BASE_CONFIG" ]; then
|
command -v hyprctl >/dev/null || { echo "[error] hyprctl not found"; exit 1; }
|
||||||
echo "[error] base config not found"
|
command -v jq >/dev/null || { echo "[error] jq not found"; exit 1; }
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
command -v hyprctl >/dev/null || {
|
cd "$WAYBAR_DIR"
|
||||||
echo "[error] hyprctl not found"
|
|
||||||
|
# -----------------------------
|
||||||
|
# 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
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
MONITORS=$(hyprctl -j monitors | jq -r '.[].name')
|
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
|
for MONITOR in $MONITORS; do
|
||||||
TARGET="$WAYBAR_DIR/config-$MONITOR"
|
TARGET="config-$MONITOR"
|
||||||
|
|
||||||
{
|
{
|
||||||
echo '{'
|
echo '{'
|
||||||
echo " \"output\": [\"$MONITOR\"],"
|
echo " \"output\": [\"$MONITOR\"],"
|
||||||
sed '1s/^{//' "$BASE_CONFIG"
|
echo "$BASE_CONTENT"
|
||||||
} > "$TARGET"
|
} > "$TARGET"
|
||||||
|
|
||||||
echo "[ok] generated $TARGET for $MONITOR"
|
echo "[ok] generated $TARGET"
|
||||||
done
|
done
|
||||||
|
|||||||
Reference in New Issue
Block a user