From a0911caacfe5dabdae8bd4bf56cf6f813550fdce Mon Sep 17 00:00:00 2001 From: "Lennart J. Kurzweg (Nx2)" Date: Thu, 27 Jun 2024 12:34:49 +0200 Subject: [PATCH] better scripts --- home-modules/hyprland.nix | 2 +- home-modules/waybar.nix | 19 +++++------ system-modules/health_reminder.nix | 51 ++++++++++++++++-------------- system-modules/nx2site.nix | 10 +++--- 4 files changed, 43 insertions(+), 39 deletions(-) diff --git a/home-modules/hyprland.nix b/home-modules/hyprland.nix index 2b5a063..af1afc6 100755 --- a/home-modules/hyprland.nix +++ b/home-modules/hyprland.nix @@ -42,7 +42,7 @@ let name = "HDMI-A-1"; resolution = "3840x2160"; position = "0x0"; - scale = "1.0"; + scale = "2.0"; }; }; }; diff --git a/home-modules/waybar.nix b/home-modules/waybar.nix index 1d25119..36a531f 100755 --- a/home-modules/waybar.nix +++ b/home-modules/waybar.nix @@ -4,9 +4,9 @@ let in lib.mkIf (user != "tv") { - home.packages = with pkgs; [ - (pkgs.writeShellScriptBin "waybar_mode" '' - #!/usr/bin/env bash + home.packages = + let + waybar_mode_script = /*bash*/ '' print_help() { echo "Usage: waybar_mode {set |unset}" } @@ -36,18 +36,19 @@ lib.mkIf (user != "tv") ;; esac exit 0 - '') - (pkgs.writeShellScriptBin "cclock" '' - #!/bin/bash - #ord=$(date +"%e" | awk '{printf("%d%s\n", $1, substr("thstndrd", ($1%100-20)%10*2+1, 2))}') + ''; + cclock_script = /*bash*/ '' ord=$(date +"%e" | awk '{printf("%d%s\n", $1, ($1==11||$1==12||$1==13)?"th":((($1%10)==1)?"st":((($1%10)==2)?"nd":((($1%10)==3)?"rd":"th"))))}') if [ $# -eq 0 ]; then echo "󰃮${sep}$(date +'%A the')" "$ord" "of" "$(date +'%B')" " ${sep}$(date +'%R')" elif [ "$1" = "--no-icons" ]; then echo "$(date +'%A the')" "$ord" "of" "$(date +'%B')" "$(date +'%R')" fi - '') - + ''; + in + with pkgs; [ + (writeShellApplication "waybar_mode" waybar_mode_script) + (writeShellApplication "cclock" cclock_script) ] ++ [ pkgs-unstable.waybar ]; programs.waybar = { diff --git a/system-modules/health_reminder.nix b/system-modules/health_reminder.nix index eec8dad..27f9ac2 100755 --- a/system-modules/health_reminder.nix +++ b/system-modules/health_reminder.nix @@ -13,40 +13,45 @@ lib.mkIf (host != "NxACE") systemd.services."health_reminder" = let - hm = pkgs.writeScriptBin "health_reminder" '' + hm = + let p = /*python*/ '' #!${pkgs.python3}/bin/python3 import random - + import re + class Action: - def __init__(self, actionA: str, actionB: str, likelihood: int, options: str): - self.actionA = actionA - self.actionB = actionB + def __init__(self, action: str, likelihood: int, options: list[str] = None): + self.action = action self.likelihood = likelihood - self.options = options - + self.options = options if options is not None else [] + def __str__(self): - if self.options: - return f"{self.actionA}{random.choice(self.options)}{self.actionB}" - else: - return self.actionA - - + try: + choice = random.choice(self.options) + except IndexError: + choice = "" + + action = re.sub("%o", choice, self.action) + return action + actions = [ - Action("look away for 20 Seconds!", "", 300, ""), - Action("Shrimp 3000!", "", 90, ""), - Action("Do ", " Biceps curls with each Arm! ", 5, ["50", "10", "20"]), - Action("Do ", " Shourlder thingees", 5, ["30", "50", "20"]), - Action("Plank for ", " senonds!", 5, ["60", "60", "70"]), - Action("Strech your upper body!", "", 10, ""), - Action("Strech your core!", "", 5, ""), - Action("Strech your legs!", "", 5, ""), - Action("Make Tea!", "", 5, ""), + Action("look away for %o Seconds!",300, ["10", "15"] ), + Action("Posture Check!", 90 ), + Action("Do %o Biceps curls!", 5, ["50", "100", "150"] ), + Action("Do %o Shourlder thingees", 5, ["40 + 40", "50", "60"]), + Action("Plank for %o senonds!", 5, ["60", "60", "70"] ), + Action("Strech your upper body!", 20 ), + Action("Strech your core!", 10 ), + Action("Strech your legs!", 10 ), + Action("Make Tea!", 5 ), + Action("Touch Grass!", 5 ) ] - + total_likelihood = sum(a.likelihood for a in actions) random_action = random.choices(actions, [a.likelihood for a in actions], k=1)[0] print(random_action) ''; + in pkgs.writeScriptBin "health_reminder" p; in { script = '' diff --git a/system-modules/nx2site.nix b/system-modules/nx2site.nix index 07dbff5..5e6e416 100644 --- a/system-modules/nx2site.nix +++ b/system-modules/nx2site.nix @@ -13,8 +13,8 @@ lib.mkIf (host == "NxACE") services."namecheap-dynamic-dns" = let u = pkgs.writeScriptBin "update_namecheap" '' - my_ip=$(curl -s https://ipinfo.io/ip) - dns_ip=$(nslookup nx2.site | grep -E "Address: [0-9]" | cut -c 10-) + my_ip=$(${pkgs.curl}/bin/curl -s https://ipinfo.io/ip) + dns_ip=$(${pkgs.dig}/bin/nslookup nx2.site | grep -E "Address: [0-9]" | cut -c 10-) fdc="/home/nx2/nx2site/domain/count.txt" force_update=false @@ -35,10 +35,8 @@ lib.mkIf (host == "NxACE") count=$(<$fdc) echo [ $count times ] $(date) from $dns_ip to $my_ip >> /home/nx2/nx2site/domain/updates.log pw=$(cat /home/nx2/nx2site/domain/pw.txt) - # cat /home/nx2/nx2site/domain/subdomain.list | parallel -j2 "curl -s 'https://dynamicdns.park-your-domain.com/update?host={}&domain=nx2.site&password=$pw&ip=$my_ip'" - curl -s "https://dynamicdns.park-your-domain.com/update?host=@&domain=nx2.site&password=$pw&ip=$my_ip" - curl -s "https://dynamicdns.park-your-domain.com/update?host=*&domain=nx2.site&password=$pw&ip=$my_ip" - echo curl -s "https://dynamicdns.park-your-domain.com/update?host=*&domain=nx2.site&password=$pw&ip=$my_ip" + ${pkgs.curl}/bin/curl -s "https://dynamicdns.park-your-domain.com/update?host=@&domain=nx2.site&password=$pw&ip=$my_ip" + ${pkgs.curl}/bin/curl -s "https://dynamicdns.park-your-domain.com/update?host=*&domain=nx2.site&password=$pw&ip=$my_ip" echo 0 > $fdc fi '';