adding hyprland/hypridle/hyprlock configuration
This commit is contained in:
3
dotfiles/.config/hypr/UserScripts/00-Readme
Executable file
3
dotfiles/.config/hypr/UserScripts/00-Readme
Executable file
@@ -0,0 +1,3 @@
|
||||
# Place your new scripts here.
|
||||
# If you need to edit a script from main script (~/.config/hypr/scripts), copy it on this directory, and edit.
|
||||
# Make sure to update as well the keybinds in ~/.config/hypr/UserConfigs directory if any script is linked to it
|
||||
146
dotfiles/.config/hypr/UserScripts/Weather.py
Executable file
146
dotfiles/.config/hypr/UserScripts/Weather.py
Executable file
@@ -0,0 +1,146 @@
|
||||
#!/usr/bin/env python3
|
||||
# HyprFlux — https://github.com/ahmad9059/HyprFlux
|
||||
# original code https://gist.github.com/Surendrajat/ff3876fd2166dd86fb71180f4e9342d7
|
||||
# weather using python
|
||||
|
||||
import requests
|
||||
import json
|
||||
import os
|
||||
from pyquery import PyQuery # install using `pip install pyquery`
|
||||
|
||||
# weather icons
|
||||
weather_icons = {
|
||||
"sunnyDay": "",
|
||||
"clearNight": "",
|
||||
"cloudyFoggyDay": "",
|
||||
"cloudyFoggyNight": "",
|
||||
"rainyDay": "",
|
||||
"rainyNight": "",
|
||||
"snowyIcyDay": "",
|
||||
"snowyIcyNight": "",
|
||||
"severe": "",
|
||||
"default": "",
|
||||
}
|
||||
|
||||
|
||||
# Get current location based on IP address
|
||||
def get_location():
|
||||
response = requests.get("https://ipinfo.io")
|
||||
data = response.json()
|
||||
loc = data["loc"].split(",")
|
||||
return float(loc[0]), float(loc[1])
|
||||
|
||||
|
||||
# Get latitude and longitude
|
||||
latitude, longitude = get_location()
|
||||
|
||||
# Open-Meteo API endpoint
|
||||
url = f"https://weather.com/en-PH/weather/today/l/{latitude},{longitude}"
|
||||
|
||||
# manual location_id
|
||||
# NOTE: if you want to add manually, make sure you disable def get_location above
|
||||
# to get your own location_id, go to https://weather.com & search your location.
|
||||
# once you choose your location, you can see the location_id in the URL(64 chars long hex string)
|
||||
# like this: https://weather.com/en-PH/weather/today/l/bca47d1099e762a012b9a139c36f30a0b1e647f69c0c4ac28b537e7ae9c1c200
|
||||
# location_id = "bca47d1099e762a012b9a139c36f30a0b1e647f69c0c4ac28b537e7ae9c1c200" # TODO
|
||||
|
||||
# NOTE to change to deg F, change the URL to your preffered location after weather.com
|
||||
# Default is English-Philippines with Busan, South Korea as location_id
|
||||
# get html page
|
||||
# url = "https://weather.com/en-PH/weather/today/l/" + location_id
|
||||
|
||||
html_data = PyQuery(url=url)
|
||||
|
||||
# current temperature
|
||||
temp = html_data("span[data-testid='TemperatureValue']").eq(0).text()
|
||||
|
||||
# current status phrase
|
||||
status = html_data("div[data-testid='wxPhrase']").text()
|
||||
status = f"{status[:16]}.." if len(status) > 17 else status
|
||||
|
||||
# status code
|
||||
status_code = html_data("#regionHeader").attr("class").split(" ")[2].split("-")[2]
|
||||
|
||||
# status icon
|
||||
icon = (
|
||||
weather_icons[status_code]
|
||||
if status_code in weather_icons
|
||||
else weather_icons["default"]
|
||||
)
|
||||
|
||||
# temperature feels like
|
||||
temp_feel = html_data(
|
||||
"div[data-testid='FeelsLikeSection'] > span > span[data-testid='TemperatureValue']"
|
||||
).text()
|
||||
temp_feel_text = f"Feels like {temp_feel}c"
|
||||
|
||||
# min-max temperature
|
||||
temp_min = (
|
||||
html_data("div[data-testid='wxData'] > span[data-testid='TemperatureValue']")
|
||||
.eq(1)
|
||||
.text()
|
||||
)
|
||||
temp_max = (
|
||||
html_data("div[data-testid='wxData'] > span[data-testid='TemperatureValue']")
|
||||
.eq(0)
|
||||
.text()
|
||||
)
|
||||
temp_min_max = f" {temp_min}\t\t {temp_max}"
|
||||
|
||||
# wind speed
|
||||
wind_speed = str(html_data("span[data-testid='Wind'] > span").text())
|
||||
wind_text = f" {wind_speed}"
|
||||
|
||||
# humidity
|
||||
humidity = html_data("span[data-testid='PercentageValue']").text()
|
||||
humidity_text = f" {humidity}"
|
||||
|
||||
# visibility
|
||||
visibility = html_data("span[data-testid='VisibilityValue']").text()
|
||||
visibility_text = f" {visibility}"
|
||||
|
||||
# air quality index
|
||||
air_quality_index = html_data("text[data-testid='DonutChartValue']").text()
|
||||
|
||||
# hourly rain prediction
|
||||
prediction = html_data("section[aria-label='Hourly Forecast']")(
|
||||
"div[data-testid='SegmentPrecipPercentage'] > span"
|
||||
).text()
|
||||
prediction = prediction.replace("Chance of Rain", "")
|
||||
prediction = f"\n\n (hourly) {prediction}" if len(prediction) > 0 else prediction
|
||||
|
||||
# tooltip text
|
||||
tooltip_text = str.format(
|
||||
"\t\t{}\t\t\n{}\n{}\n{}\n\n{}\n{}\n{}{}",
|
||||
f'<span size="xx-large">{temp}</span>',
|
||||
f"<big> {icon}</big>",
|
||||
f"<b>{status}</b>",
|
||||
f"<small>{temp_feel_text}</small>",
|
||||
f"<b>{temp_min_max}</b>",
|
||||
f"{wind_text}\t{humidity_text}",
|
||||
f"{visibility_text}\tAQI {air_quality_index}",
|
||||
f"<i> {prediction}</i>",
|
||||
)
|
||||
|
||||
# print waybar module data
|
||||
out_data = {
|
||||
"text": f"{icon} {temp}",
|
||||
"alt": status,
|
||||
"tooltip": tooltip_text,
|
||||
"class": status_code,
|
||||
}
|
||||
print(json.dumps(out_data))
|
||||
|
||||
simple_weather = (
|
||||
f"{icon} {status}\n"
|
||||
+ f" {temp} ({temp_feel_text})\n"
|
||||
+ f"{wind_text} \n"
|
||||
+ f"{humidity_text} \n"
|
||||
+ f"{visibility_text} AQI{air_quality_index}\n"
|
||||
)
|
||||
|
||||
try:
|
||||
with open(os.path.expanduser("~/.cache/.weather_cache"), "w") as file:
|
||||
file.write(simple_weather)
|
||||
except Exception as e:
|
||||
print(f"Error writing to cache: {e}")
|
||||
87
dotfiles/.config/hypr/UserScripts/Weather.sh
Executable file
87
dotfiles/.config/hypr/UserScripts/Weather.sh
Executable file
@@ -0,0 +1,87 @@
|
||||
#!/bin/bash
|
||||
# HyprFlux — https://github.com/ahmad9059/HyprFlux
|
||||
# weather info from wttr. https://github.com/chubin/wttr.in
|
||||
# Remember to add city
|
||||
|
||||
city=
|
||||
cachedir="$HOME/.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]}"\"}"
|
||||
|
||||
cached_weather=" $temperature \n$condition ${weather[1]}"
|
||||
|
||||
echo -e $cached_weather > "$HOME/.cache/.weather_cache"
|
||||
69
dotfiles/.config/hypr/UserScripts/ZshChangeTheme.sh
Executable file
69
dotfiles/.config/hypr/UserScripts/ZshChangeTheme.sh
Executable file
@@ -0,0 +1,69 @@
|
||||
#!/bin/bash
|
||||
# HyprFlux — https://github.com/ahmad9059/HyprFlux
|
||||
# Script for Oh my ZSH theme ( CTRL SHIFT O)
|
||||
|
||||
# preview of theme can be view here: https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
|
||||
# after choosing theme, TTY need to be closed and re-open
|
||||
|
||||
# Variables
|
||||
iDIR="$HOME/.config/swaync/images"
|
||||
rofi_theme="$HOME/.config/rofi/config-zsh-theme.rasi"
|
||||
|
||||
if [ -n "$(grep -i nixos < /etc/os-release)" ]; then
|
||||
notify-send -i "$iDIR/note.png" "NOT Supported" "Sorry NixOS does not support this HyprFlux feature"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
themes_dir="$HOME/.oh-my-zsh/themes"
|
||||
file_extension=".zsh-theme"
|
||||
|
||||
|
||||
themes_array=($(find -L "$themes_dir" -type f -name "*$file_extension" -exec basename {} \; | sed -e "s/$file_extension//"))
|
||||
|
||||
# Add "Random" option to the beginning of the array
|
||||
themes_array=("Random" "${themes_array[@]}")
|
||||
|
||||
rofi_command="rofi -i -dmenu -config $rofi_theme"
|
||||
|
||||
menu() {
|
||||
for theme in "${themes_array[@]}"; do
|
||||
echo "$theme"
|
||||
done
|
||||
}
|
||||
|
||||
main() {
|
||||
choice=$(menu | ${rofi_command})
|
||||
|
||||
# if nothing selected, script won't change anything
|
||||
if [ -z "$choice" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
zsh_path="$HOME/.zshrc"
|
||||
var_name="ZSH_THEME"
|
||||
|
||||
if [[ "$choice" == "Random" ]]; then
|
||||
# Pick a random theme from the original themes_array (excluding "Random")
|
||||
random_theme=${themes_array[$((RANDOM % (${#themes_array[@]} - 1) + 1))]}
|
||||
theme_to_set="$random_theme"
|
||||
notify-send -i "$iDIR/ja.png" "Random theme:" "selected: $random_theme"
|
||||
else
|
||||
# Set theme to the selected choice
|
||||
theme_to_set="$choice"
|
||||
notify-send -i "$iDIR/ja.png" "Theme selected:" "$choice"
|
||||
fi
|
||||
|
||||
if [ -f "$zsh_path" ]; then
|
||||
sed -i "s/^$var_name=.*/$var_name=\"$theme_to_set\"/" "$zsh_path"
|
||||
notify-send -i "$iDIR/ja.png" "OMZ theme" "applied. restart your terminal"
|
||||
else
|
||||
notify-send -i "$iDIR/error.png" "E-R-R-O-R" "~.zshrc file not found!"
|
||||
fi
|
||||
}
|
||||
|
||||
# Check if rofi is already running
|
||||
if pidof rofi > /dev/null; then
|
||||
pkill rofi
|
||||
fi
|
||||
|
||||
main
|
||||
Reference in New Issue
Block a user