Skip to content

Instantly share code, notes, and snippets.

@skorotkiewicz
Last active June 3, 2025 06:44
Show Gist options
  • Save skorotkiewicz/a4738ca267c16ab455b3bee8768db392 to your computer and use it in GitHub Desktop.
Save skorotkiewicz/a4738ca267c16ab455b3bee8768db392 to your computer and use it in GitHub Desktop.
my tint2 executors
ping -c 1 ipv4.google.com | grep -oP 'time=\K[0-9.]+ ms'
#!/bin/bash
# Main menu
yad --title="System Shutdown" \
--button="Shut Down:1" \
--button="Restart:2" \
--button="Log Out:3" \
--width=300 --height=100 \
--center \
--text="Choose an action:"
# Save the exit code (i.e., which button was pressed)
exit_code=$?
# Confirmation function
confirm() {
yad --title="Confirmation" \
--center \
--width=300 \
--height=100 \
--button="Yes":0 \
--button="No":1 \
--text="Are you sure you want to $1?"
return $?
}
# Handle selection
case "$exit_code" in
1)
if confirm "shut down the computer"; then
systemctl poweroff
fi
;;
2)
if confirm "restart the computer"; then
systemctl reboot
fi
;;
3)
if confirm "log out"; then
pkill -KILL -u "$USER"
fi
;;
*)
echo "Cancelled or window closed."
;;
esac
#!/bin/bash
LATITUDE=48.8082
LONGITUDE=11.7551
URL="https://api.met.no/weatherapi/locationforecast/2.0/compact?lat=${LATITUDE}&lon=${LONGITUDE}"
USER_AGENT="Mozilla/5.0 ([email protected])"
# Function to get current temperature
get_current_temp() {
TEMP=$(curl -s -H "User-Agent: $USER_AGENT" "$URL" | \
jq -r '.properties.timeseries[0].data.instant.details.air_temperature')
echo "${TEMP}°C"
}
# Function to display weekly forecast in YAD
show_weekly_forecast() {
# Fetch weather data
WEATHER_DATA=$(curl -s -H "User-Agent: $USER_AGENT" "$URL")
# Prepare data for display
FORECAST=""
# Get forecasts for next 7 days (every 24 hours)
for i in {0..6}; do
# Calculate index for 24h intervals (API returns hourly data)
INDEX=$((i * 24))
# Get data for specific day
DATETIME=$(echo "$WEATHER_DATA" | jq -r ".properties.timeseries[$INDEX].time" 2>/dev/null)
if [ "$DATETIME" == "null" ] || [ -z "$DATETIME" ]; then
continue
fi
TEMP=$(echo "$WEATHER_DATA" | jq -r ".properties.timeseries[$INDEX].data.instant.details.air_temperature" 2>/dev/null)
HUMIDITY=$(echo "$WEATHER_DATA" | jq -r ".properties.timeseries[$INDEX].data.instant.details.relative_humidity" 2>/dev/null)
WIND_SPEED=$(echo "$WEATHER_DATA" | jq -r ".properties.timeseries[$INDEX].data.instant.details.wind_speed" 2>/dev/null)
# Get weather symbol (if available)
SYMBOL=$(echo "$WEATHER_DATA" | jq -r ".properties.timeseries[$INDEX].data.next_1_hours.summary.symbol_code" 2>/dev/null)
if [ "$SYMBOL" == "null" ]; then
SYMBOL=$(echo "$WEATHER_DATA" | jq -r ".properties.timeseries[$INDEX].data.next_6_hours.summary.symbol_code" 2>/dev/null)
fi
# Format date
DATE=$(date -d "$DATETIME" "+%A, %d.%m.%Y" 2>/dev/null)
if [ -z "$DATE" ]; then
DATE=$(echo "$DATETIME" | cut -d'T' -f1)
fi
# Add to forecast
FORECAST="${FORECAST}📅 $DATE\n"
FORECAST="${FORECAST}🌡️ Temperature: ${TEMP}°C\n"
FORECAST="${FORECAST}💧 Humidity: ${HUMIDITY}%\n"
FORECAST="${FORECAST}💨 Wind: ${WIND_SPEED} m/s\n"
if [ "$SYMBOL" != "null" ] && [ -n "$SYMBOL" ]; then
FORECAST="${FORECAST}☁️ Conditions: $SYMBOL\n"
fi
FORECAST="${FORECAST}\n"
done
# Display in YAD
echo -e "$FORECAST" | yad --text-info \
--title="Weekly Weather Forecast" \
--width=500 \
--height=400 \
--button="Close:0" \
--fontname="Monospace 10"
}
# Check arguments
case "$1" in
"forecast")
show_weekly_forecast
;;
*)
get_current_temp
;;
esac
LATITUDE=48.8082
LONGITUDE=11.7551
URL="https://api.met.no/weatherapi/locationforecast/2.0/compact?lat=${LATITUDE}&lon=${LONGITUDE}"
USER_AGENT="Mozilla/5.0 ([email protected])"
TEMP=$(curl -s -H "User-Agent: $USER_AGENT" "$URL" | \
jq -r '.properties.timeseries[0].data.instant.details.air_temperature')
echo "${TEMP}°C"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment