From 22cedc6712d690664ff5ead10309f0aa166f97b9 Mon Sep 17 00:00:00 2001 From: Timo Bingmann Date: Mon, 8 Dec 2025 23:47:02 -0800 Subject: [PATCH] tb-scripts: add ,optipng and ,zipdir utility scripts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add two new shell utility scripts to the custom script packages: ,optipng - Parallel PNG optimization wrapper - Detects available CPU cores and runs optipng in parallel using xargs - Accepts optional file arguments, defaults to all *.png in current dir - Uses maximum compression level (-o7) for best results - Added to tb-dev-scripts package with optipng as runtime dependency ,zipdir - Quick directory archiving helper - Creates a zip archive of the current directory - Names the archive after the directory and places it in parent folder - Uses maximum compression (-9) with extra attributes excluded (-X) - Added to tb-scripts package with zip as runtime dependency 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- pkgs/tb-dev-scripts/default.nix | 6 ++++++ pkgs/tb-dev-scripts/optipng | 13 +++++++++++++ pkgs/tb-scripts/default.nix | 5 +++++ pkgs/tb-scripts/zipdir | 3 +++ 4 files changed, 27 insertions(+) create mode 100755 pkgs/tb-dev-scripts/optipng create mode 100755 pkgs/tb-scripts/zipdir diff --git a/pkgs/tb-dev-scripts/default.nix b/pkgs/tb-dev-scripts/default.nix index 0d5ebdf..b0eeb3b 100644 --- a/pkgs/tb-dev-scripts/default.nix +++ b/pkgs/tb-dev-scripts/default.nix @@ -20,5 +20,11 @@ pkgs.symlinkJoin { "--prefix PATH : ${lib.makeBinPath [ pkgs.ffmpeg ]}" ]; } (builtins.readFile ./video_loop_extractor.py)) + + (pkgs.writeShellApplication { + name = ",optipng"; + runtimeInputs = [ pkgs.optipng ]; + text = builtins.readFile ./optipng; + }) ]; } diff --git a/pkgs/tb-dev-scripts/optipng b/pkgs/tb-dev-scripts/optipng new file mode 100755 index 0000000..321e79b --- /dev/null +++ b/pkgs/tb-dev-scripts/optipng @@ -0,0 +1,13 @@ +#!/bin/sh -x + +PROCS=$(grep -c ^processor /proc/cpuinfo) + +if [ -z "$@" ]; then + (for f in *.png; do + echo "$f"; + done) | xargs -P$PROCS -d'\n' -n1 optipng -o7 +else + (for f in "$@"; do + echo "$f"; + done) | xargs -P$PROCS -d'\n' -n1 optipng -o7 +fi diff --git a/pkgs/tb-scripts/default.nix b/pkgs/tb-scripts/default.nix index d13b71e..a6efd3c 100644 --- a/pkgs/tb-scripts/default.nix +++ b/pkgs/tb-scripts/default.nix @@ -15,5 +15,10 @@ pkgs.symlinkJoin { (pkgs.writers.writePython3Bin ",rename_lower" { libraries = [ ]; } (builtins.readFile ./rename_lower.py)) + (pkgs.writeShellApplication { + name = ",zipdir"; + runtimeInputs = [ pkgs.zip ]; + text = builtins.readFile ./zipdir; + }) ]; } diff --git a/pkgs/tb-scripts/zipdir b/pkgs/tb-scripts/zipdir new file mode 100755 index 0000000..cc2c134 --- /dev/null +++ b/pkgs/tb-scripts/zipdir @@ -0,0 +1,3 @@ +#!/bin/sh + +zip -9rX "../$(basename "$PWD").zip" .