home-manager, pkgs: convert uptime script to proper package
All checks were successful
flake / build (push) Successful in 6m12s

Signed-off-by: Christoph Heiss <christoph@c8h4.io>
This commit is contained in:
Christoph Heiss 2024-11-18 11:05:30 +01:00
parent a899889768
commit ccac857f21
Signed by: c8h4
GPG key ID: 1538094429952F86
4 changed files with 38 additions and 29 deletions

View file

@ -9,6 +9,7 @@
neomutt-export-patches = callPackage ./neomutt-export-patches { };
note-mark = callPackage ./note-mark { };
sway-background-image = callPackage ./sway-background-image.nix { };
uptime-pretty = callPackage ./uptime-pretty { };
# Pin to older version until
# https://github.com/nix-community/home-manager/pull/5918

View file

@ -0,0 +1,7 @@
{ coreutils, writeShellApplication }:
writeShellApplication {
name = "uptime-pretty";
runtimeInputs = [ coreutils ];
text = builtins.readFile ./uptime-pretty.sh;
}

View file

@ -0,0 +1,26 @@
# shellcheck shell=bash
HOUR=$((60 * 60))
DAY=$((HOUR * 24))
WEEK=$((DAY * 7))
raw=$(cut -d' ' -f1 </proc/uptime | cut -d. -f1)
printf 'up '
if [[ $raw -gt $WEEK ]]; then
printf '%dw ' $((raw / WEEK))
raw=$((raw % WEEK))
fi
if [[ $raw -gt $DAY ]]; then
printf '%dd ' $((raw / DAY))
raw=$((raw % DAY))
fi
if [[ $raw -gt $HOUR ]]; then
printf '%dh ' $((raw / HOUR))
raw=$((raw % HOUR))
fi
printf %dmin $((raw / 60))

View file

@ -1,33 +1,6 @@
{ lib, pkgs, ... }:
let
tmuxPrettyUptimeSh = pkgs.writeShellScript "tmux-pretty-uptime" ''
HOUR=$((60 * 60))
DAY=$((HOUR * 24))
WEEK=$((DAY * 7))
raw=$(cut -d' ' -f1 </proc/uptime | cut -d. -f1)
printf 'up '
if [[ $raw -gt $WEEK ]]; then
printf '%dw ' $((raw / WEEK))
raw=$((raw % WEEK))
fi
if [[ $raw -gt $DAY ]]; then
printf '%dd ' $((raw / DAY))
raw=$((raw % DAY))
fi
if [[ $raw -gt $HOUR ]]; then
printf '%dh ' $((raw / HOUR))
raw=$((raw % HOUR))
fi
printf %dmin $((raw / 60))
'';
in {
{
home.stateVersion = "23.05";
# `programs.home-manager.enable = true` does not seem to work correctly ..
@ -132,7 +105,9 @@ in {
#[fg=orange]#{?client_prefix,^A, }#[default]"
set-option -g status-right \
'#[fg=darkred]#[fg=brightwhite,bg=darkred] #(${tmuxPrettyUptimeSh}) \
'#[fg=darkred]#[fg=brightwhite,bg=darkred] #(${
lib.getExe pkgs.uptime-pretty
}) \
#[fg=colour59,bg=darkred]#[fg=brightwhite,bg=colour59] %a %I:%M:%S %p #[fg=blue]#[fg=brightwhite,bg=blue] %Y-%m-%d '
'';
}