From c21e5736d8f4a2a98ed4cc8d9d7f0f4b92e5bc8f Mon Sep 17 00:00:00 2001 From: antistereov Date: Wed, 25 Feb 2026 00:16:54 +0100 Subject: [PATCH] feat: add battery and weather script --- hypr/hyprlock.conf | 14 +++++- kitty/kitty.conf | 2 +- waybar/config.jsonc | 13 ++++- waybar/scripts/battery.sh | 55 ++++++++++++++++++++ waybar/scripts/weather.sh | 102 ++++++++++++++++++++++++++++++++++++++ waybar/style.css | 1 + 6 files changed, 183 insertions(+), 4 deletions(-) create mode 100755 waybar/scripts/battery.sh create mode 100755 waybar/scripts/weather.sh diff --git a/hypr/hyprlock.conf b/hypr/hyprlock.conf index 42c3ec6..d0824a3 100644 --- a/hypr/hyprlock.conf +++ b/hypr/hyprlock.conf @@ -51,14 +51,24 @@ label { # BATTERY label { monitor = - text = cmd[update:30000] echo "󰁹 $(cat /sys/class/power_supply/BAT1/capacity)%" - font_family = Lexend + text = cmd[update:1000] echo "$(~/.config/waybar/scripts/battery.sh)" + font_family = lexend font_size = 14 position = -100, 100 halign = right valign = bottom } +label { + monitor = + text = cmd[update:600000] echo "$(~/.config/waybar/scripts/weather.sh | jq -r .text)" + font_family = lexend + font_size = 14 + position = -200, 100 + halign = right + valign = bottom +} + input-field { monitor = size = 300, 50 diff --git a/kitty/kitty.conf b/kitty/kitty.conf index bd5185f..43c88d1 100644 --- a/kitty/kitty.conf +++ b/kitty/kitty.conf @@ -6,7 +6,7 @@ copy_on_select yes map ctrl+v paste_from_clipboard # Font -font_size 13.0 +font_size 11.0 # Nerd Fonts v3.3.0 symbol_map U+e000-U+e00a,U+ea60-U+ebeb,U+e0a0-U+e0c8,U+e0ca,U+e0cc-U+e0d7,U+e200-U+e2a9,U+e300-U+e3e3,U+e5fa-U+e6b7,U+e700-U+e8ef,U+ed00-U+efc1,U+f000-U+f2ff,U+f000-U+f2e0,U+f300-U+f381,U+f400-U+f533,U+f0001-U+f1af0 Symbols Nerd Font Mono diff --git a/waybar/config.jsonc b/waybar/config.jsonc index 28e13dc..400e9ba 100644 --- a/waybar/config.jsonc +++ b/waybar/config.jsonc @@ -14,6 +14,7 @@ "memory", "pulseaudio", "clock", + "custom/weather", "clock#simpleclock", "custom/tailscale", "network", @@ -51,7 +52,7 @@ "window-rewrite": { "class<*>": "󰘔 ", "class": "󰈹 ", - "class": " " , + "class": "󰖟 " , "class": "󰨞 ", "class": "󰆍 ", "class": "󰓇 ", @@ -60,6 +61,9 @@ "class": "󰅟 ", "class": " ", "class": " ", + "class": " ", + "class": " ", + "class": " " } }, "hyprland/window": { @@ -152,6 +156,13 @@ "return-type": "json", "tooltip": false, }, + "custom/weather": { + "format": "{}", + "interval": 600, + "exec": "~/.config/waybar/scripts/weather.sh", // or your dotfiles folder if you use stow + "return-type": "json", + "on-click": "gnome-weather" + }, "custom/tailscale": { "exec": "~/.config/waybar/scripts/tailscale.sh", "interval": 5, diff --git a/waybar/scripts/battery.sh b/waybar/scripts/battery.sh new file mode 100755 index 0000000..a1e6a2e --- /dev/null +++ b/waybar/scripts/battery.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Find battery + AC device (works on most laptops) +BAT="$(ls -1 /sys/class/power_supply 2>/dev/null | grep -E '^BAT|^CMB|^BATT' | head -n1 || true)" +AC="$(ls -1 /sys/class/power_supply 2>/dev/null | grep -E '^AC|^ADP|^ACAD' | head -n1 || true)" + +if [[ -z "${BAT}" ]]; then + echo " --%" # unknown + exit 0 +fi + +BAT_PATH="/sys/class/power_supply/${BAT}" +STATUS="$(<"${BAT_PATH}/status")" # Charging|Discharging|Full|Not charging|Unknown +CAPACITY="$(<"${BAT_PATH}/capacity")" # 0-100 + +#  0-10,  11-35,  36-60,  61-85,  86-100 +if ((CAPACITY <= 10)); then + if [[ "${STATUS}" == "Charging" ]]; then + ICON="󰢜 " + else + ICON="󰁺 " + fi +elif ((CAPACITY <= 30)); then + if [[ "${STATUS}" == "Charging" ]]; then + ICON="󰂇 " + else + ICON="󰁼 " + fi +elif ((CAPACITY <= 60)); then + if [[ "${STATUS}" == "Charging" ]]; then + ICON="󰂉 " + else + ICON="󰁿 " + fi +elif ((CAPACITY <= 80)); then + if [[ "${STATUS}" == "Charging" ]]; then + ICON="󰂊 " + else + ICON="󰂁 " + fi +else + if [[ "${STATUS}" == "Charging" ]]; then + ICON="󰂅 " + else + ICON="󰁹 " + fi +fi + +# If full, show a nicer indicator +if [[ "${STATUS}" == "Full" ]]; then + CHG_IND=" " # nf-fa-check +fi + +echo "${ICON} ${CAPACITY}%" diff --git a/waybar/scripts/weather.sh b/waybar/scripts/weather.sh new file mode 100755 index 0000000..89600dc --- /dev/null +++ b/waybar/scripts/weather.sh @@ -0,0 +1,102 @@ +#!/bin/bash + +# --- CONFIGURATION --- +LAT="51.0509" # Replace with your Latitude +LON="13.7383" # Replace with your Longitude +UNITS="metric" # Use "metric" for Celsius, "imperial" for Fahrenheit +TZ="Europe/Berlin" +# --------------------- + +if [[ "$UNITS" == "metric" ]]; then + TEMP_UNIT="celsius" + LABEL="°C" +else + TEMP_UNIT="fahrenheit" + LABEL="°F" +fi + +# Fetch the weather data +RESPONSE=$(curl -s "https://api.open-meteo.com/v1/forecast?latitude=${LAT}&longitude=${LON}¤t=temperature_2m,weather_code,is_day&timezone=${TZ}") + +# Check if curl failed to get a response +if [ -z "$RESPONSE" ]; then + echo "No connection" + exit 1 +fi + +TEMP=$(echo "$RESPONSE" | jq -r '.current.temperature_2m | round') +CODE=$(echo "$RESPONSE" | jq -r '.current.weather_code') +IS_DAY=$(echo "$RESPONSE" | jq -r '.current.is_day') + +case "$CODE" in +0) + if [[ "$IS_DAY" == "1" ]]; then + ICON=" " # nf-weather-day_sunny + else + ICON=" " # nf-weather-night_clear + fi + DESC="Clear sky" + ;; +1 | 2) + if [[ "$IS_DAY" == "1" ]]; then + ICON=" " # nf-weather-day_cloudy + else + ICON=" " # nf-weather-night_alt_cloudy + fi + DESC="Partly cloudy" + ;; +3) + ICON=" " # nf-weather-cloudy + DESC="Overcast" + ;; +45 | 48) + ICON=" " # nf-weather-fog + DESC="Fog" + ;; +51 | 53 | 55) + ICON=" " # nf-weather-sprinkle + DESC="Drizzle" + ;; +56 | 57) + ICON=" " + DESC="Freezing drizzle" + ;; +61 | 63 | 65) + ICON=" " # nf-weather-rain + DESC="Rain" + ;; +66 | 67) + ICON=" " + DESC="Freezing rain" + ;; +71 | 73 | 75 | 77) + ICON=" " # nf-weather-snow + DESC="Snow" + ;; +80 | 81 | 82) + ICON=" " # nf-weather-showers + DESC="Rain showers" + ;; +85 | 86) + ICON=" " + DESC="Snow showers" + ;; +95) + ICON=" " # nf-weather-thunderstorm + DESC="Thunderstorm" + ;; +96 | 99) + ICON=" " + DESC="Thunderstorm with hail" + ;; +esac + +# Determine unit label +if [ "$UNITS" = "metric" ]; then + LABEL="°C" +else + LABEL="°F" +fi + +# Final JSON output for Waybar +echo "{\"text\": \"${ICON} ${TEMP}${LABEL}\", \"tooltip\": \"${DESC}\"}" diff --git a/waybar/style.css b/waybar/style.css index 02e8122..f6669e6 100644 --- a/waybar/style.css +++ b/waybar/style.css @@ -78,6 +78,7 @@ window#waybar { #custom-spotify, #custom-notification, #custom-tailscale, +#custom-weather, #cpu, #tray, #memory,