From f0771edf369d3ea51e3322acb9a5baa456f732b1 Mon Sep 17 00:00:00 2001 From: "Ja.KooLit" Date: Fri, 29 Dec 2023 00:41:08 +0900 Subject: Re-Structured Hypr Folder in preparation for Updates Scripts --- config/hypr/UserScripts/RainbowBorders.sh | 10 +++ config/hypr/UserScripts/Weather.py | 122 ++++++++++++++++++++++++++++++ config/hypr/UserScripts/Weather.sh | 80 ++++++++++++++++++++ config/hypr/UserScripts/ZshChangeTheme.sh | 38 ++++++++++ 4 files changed, 250 insertions(+) create mode 100755 config/hypr/UserScripts/RainbowBorders.sh create mode 100755 config/hypr/UserScripts/Weather.py create mode 100755 config/hypr/UserScripts/Weather.sh create mode 100755 config/hypr/UserScripts/ZshChangeTheme.sh (limited to 'config/hypr/UserScripts') diff --git a/config/hypr/UserScripts/RainbowBorders.sh b/config/hypr/UserScripts/RainbowBorders.sh new file mode 100755 index 00000000..1f5e6cdb --- /dev/null +++ b/config/hypr/UserScripts/RainbowBorders.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +function random_hex() { + random_hex=("0xff$(openssl rand -hex 3)") + echo $random_hex +} + +hyprctl keyword general:col.active_border $(random_hex) $(random_hex) $(random_hex) $(random_hex) $(random_hex) $(random_hex) $(random_hex) $(random_hex) $(random_hex) $(random_hex) 270deg + +hyprctl keyword general:col.inactive_border $(random_hex) $(random_hex) $(random_hex) $(random_hex) $(random_hex) $(random_hex) $(random_hex) $(random_hex) $(random_hex) $(random_hex) 270deg \ No newline at end of file diff --git a/config/hypr/UserScripts/Weather.py b/config/hypr/UserScripts/Weather.py new file mode 100755 index 00000000..154c1589 --- /dev/null +++ b/config/hypr/UserScripts/Weather.py @@ -0,0 +1,122 @@ +#!/usr/bin/env python3 +# From https://raw.githubusercontent.com/rxyhn/dotfiles/main/home/rxyhn/modules/desktop/waybar/scripts/waybar-wttr.py + +## ensure to insert city inside "" +city = "" +import json +import requests +from datetime import datetime + +WEATHER_CODES = { + '113': '', + '116': '󰖕', + '119': '', + '122': '', + '143': '', + '176': '', + '179': '', + '182': '', + '185': '', + '200': '⛈️', + '227': '🌨️', + '230': '🌨️', + '248': '☁️ ', + '260': '☁️', + '263': '🌧️', + '266': '🌧️', + '281': '🌧️', + '284': '🌧️', + '293': '🌧️', + '296': '🌧️', + '299': '🌧️', + '302': '🌧️', + '305': '🌧️', + '308': '🌧️', + '311': '🌧️', + '314': '🌧️', + '317': '🌧️', + '320': '🌨️', + '323': '🌨️', + '326': '🌨️', + '329': '❄️', + '332': '❄️', + '335': '❄️', + '338': '❄️', + '350': '🌧️', + '353': '🌧️', + '356': '🌧️', + '359': '🌧️', + '362': '🌧️', + '365': '🌧️', + '368': '🌧️', + '371': '❄️', + '374': '🌨️', + '377': '🌨️', + '386': '🌨️', + '389': '🌨️', + '392': '🌧️', + '395': '❄️' +} + +data = {} + + +weather = requests.get(f"https://wttr.in/{city}?format=j1").json() + + +def format_time(time): + return time.replace("00", "").zfill(2) + + +def format_temp(temp): + return (hour['FeelsLikeC']+"°").ljust(3) + + +def format_chances(hour): + chances = { + "chanceoffog": "Fog", + "chanceoffrost": "Frost", + "chanceofovercast": "Overcast", + "chanceofrain": "Rain", + "chanceofsnow": "Snow", + "chanceofsunshine": "Sunshine", + "chanceofthunder": "Thunder", + "chanceofwindy": "Wind" + } + + conditions = [] + for event in chances.keys(): + if int(hour[event]) > 0: + conditions.append(chances[event]+" "+hour[event]+"%") + return ", ".join(conditions) + +tempint = int(weather['current_condition'][0]['FeelsLikeC']) +extrachar = '' +if tempint > 0 and tempint < 10: + extrachar = '+' + + +data['text'] = ' '+WEATHER_CODES[weather['current_condition'][0]['weatherCode']] + \ + " "+extrachar+weather['current_condition'][0]['FeelsLikeC']+"°" + +data['tooltip'] = f"{weather['current_condition'][0]['weatherDesc'][0]['value']} {weather['current_condition'][0]['temp_C']}°\n" +data['tooltip'] += f"Feels like: {weather['current_condition'][0]['FeelsLikeC']}°\n" +data['tooltip'] += f"Wind: {weather['current_condition'][0]['windspeedKmph']}Km/h\n" +data['tooltip'] += f"Humidity: {weather['current_condition'][0]['humidity']}%\n" +for i, day in enumerate(weather['weather']): + data['tooltip'] += f"\n" + if i == 0: + data['tooltip'] += "Today, " + if i == 1: + data['tooltip'] += "Tomorrow, " + data['tooltip'] += f"{day['date']}\n" + data['tooltip'] += f"⬆️{day['maxtempC']}° ⬇️{day['mintempC']}° " + data['tooltip'] += f"🌅{day['astronomy'][0]['sunrise']} 🌇{day['astronomy'][0]['sunset']}\n" + for hour in day['hourly']: + if i == 0: + if int(format_time(hour['time'])) < datetime.now().hour-2: + continue + data['tooltip'] += f"{format_time(hour['time'])} {WEATHER_CODES[hour['weatherCode']]} {format_temp(hour['FeelsLikeC'])} {hour['weatherDesc'][0]['value']}, {format_chances(hour)}\n" + + +print(json.dumps(data)) diff --git a/config/hypr/UserScripts/Weather.sh b/config/hypr/UserScripts/Weather.sh new file mode 100755 index 00000000..40048710 --- /dev/null +++ b/config/hypr/UserScripts/Weather.sh @@ -0,0 +1,80 @@ +#!/bin/bash + +city= +cachedir=~/.cache/rbn +cachefile=${0##*/}-$1 + +if [ ! -d $cachedir ]; then + mkdir -p $cachedir +fi + +if [ ! -f $cachedir/$cachefile ]; then + touch $cachedir/$cachefile +fi + +# Save current IFS +SAVEIFS=$IFS +# Change IFS to new line. +IFS=$'\n' + +cacheage=$(($(date +%s) - $(stat -c '%Y' "$cachedir/$cachefile"))) +if [ $cacheage -gt 1740 ] || [ ! -s $cachedir/$cachefile ]; then + data=($(curl -s https://en.wttr.in/"$city"$1\?0qnT 2>&1)) + echo ${data[0]} | cut -f1 -d, > $cachedir/$cachefile + echo ${data[1]} | sed -E 's/^.{15}//' >> $cachedir/$cachefile + echo ${data[2]} | sed -E 's/^.{15}//' >> $cachedir/$cachefile +fi + +weather=($(cat $cachedir/$cachefile)) + +# Restore IFSClear +IFS=$SAVEIFS + +temperature=$(echo ${weather[2]} | sed -E 's/([[:digit:]]+)\.\./\1 to /g') + +#echo ${weather[1]##*,} + +# https://fontawesome.com/icons?s=solid&c=weather +case $(echo ${weather[1]##*,} | tr '[:upper:]' '[:lower:]') in +"clear" | "sunny") + condition="" + ;; +"partly cloudy") + condition="󰖕" + ;; +"cloudy") + condition="" + ;; +"overcast") + condition="" + ;; +"fog" | "freezing fog") + condition="" + ;; +"patchy rain possible" | "patchy light drizzle" | "light drizzle" | "patchy light rain" | "light rain" | "light rain shower" | "mist" | "rain") + condition="󰼳" + ;; +"moderate rain at times" | "moderate rain" | "heavy rain at times" | "heavy rain" | "moderate or heavy rain shower" | "torrential rain shower" | "rain shower") + condition="" + ;; +"patchy snow possible" | "patchy sleet possible" | "patchy freezing drizzle possible" | "freezing drizzle" | "heavy freezing drizzle" | "light freezing rain" | "moderate or heavy freezing rain" | "light sleet" | "ice pellets" | "light sleet showers" | "moderate or heavy sleet showers") + condition="󰼴" + ;; +"blowing snow" | "moderate or heavy sleet" | "patchy light snow" | "light snow" | "light snow showers") + condition="󰙿" + ;; +"blizzard" | "patchy moderate snow" | "moderate snow" | "patchy heavy snow" | "heavy snow" | "moderate or heavy snow with thunder" | "moderate or heavy snow showers") + condition="" + ;; +"thundery outbreaks possible" | "patchy light rain with thunder" | "moderate or heavy rain with thunder" | "patchy light snow with thunder") + condition="" + ;; +*) + condition="" + echo -e "{\"text\":\""$condition"\", \"alt\":\""${weather[0]}"\", \"tooltip\":\""${weather[0]}: $temperature ${weather[1]}"\"}" + ;; +esac + +#echo $temp $condition + +echo -e "{\"text\":\""$temperature $condition"\", \"alt\":\""${weather[0]}"\", \"tooltip\":\""${weather[0]}: $temperature ${weather[1]}"\"}" diff --git a/config/hypr/UserScripts/ZshChangeTheme.sh b/config/hypr/UserScripts/ZshChangeTheme.sh new file mode 100755 index 00000000..7057ed2e --- /dev/null +++ b/config/hypr/UserScripts/ZshChangeTheme.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +themes_dir="$HOME/.oh-my-zsh/themes" +file_extension=".zsh-theme" + +themes_array=($(find "$themes_dir" -type f -name "*$file_extension" -exec basename {} \; | sed -e "s/$file_extension//")) + +rofi_command="rofi -dmenu -config ~/.config/rofi/config-zsh-theme.rasi" + +menu() { + for theme in "${themes_array[@]}"; do + echo "$theme" + done +} + +main() { + choice=$(menu | ${rofi_command}) + + # if nothing selected, script wont change anything + if [ -z "$choice" ]; then + exit 0 + fi + + zsh_path="$HOME/.zshrc" + var_name="ZSH_THEME" + for i in "${themes_array[@]}"; do + if [[ "$i" == "$choice"* ]]; then + if [ -f "$zsh_path" ]; then + sed -i "s/^$var_name=.*/$var_name=\"$i\"/" "$zsh_path" + else + echo "File not found" + fi + break + fi + done +} + +main -- cgit v1.2.3