From 5a63692092e5ca3fd4a62ce90769a413d39fe47a Mon Sep 17 00:00:00 2001 From: schmeeve Date: Wed, 17 Jun 2026 19:41:31 -0700 Subject: [PATCH] progress bars --- dedupe | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 76 insertions(+), 2 deletions(-) diff --git a/dedupe b/dedupe index 9a04bad..1953e3c 100755 --- a/dedupe +++ b/dedupe @@ -1,4 +1,5 @@ -#!/bin/sh +#!/bin/bash +VERSION=$(date -r "$0" '+%Y-%m-%d') depth="-maxdepth 1" dry_run="" @@ -20,7 +21,78 @@ while [ $# -gt 0 ]; do shift done -find . $depth -type f -exec md5sum {} + | sort | awk -v dry_run="${dry_run:-0}" ' +# colors +YEL=$'\033[1;33m' +BLU=$'\033[1;34m' +CYN=$'\033[1;36m' +WHT=$'\033[1;37m' +DIM=$'\033[2;37m' +RED=$'\033[1;31m' +RST=$'\033[0m' + +progress_bar() { + local current=$1 + local total=$2 + local width=36 + + local pct filled + if [ "$total" -eq 0 ]; then + pct=100; filled=$width + else + pct=$((current * 100 / total)) + filled=$((current * width / total)) + fi + local empty=$((width - filled)) + + # Pac-Man mouth alternates open/closed + local pac + if (( current % 2 == 0 )); then pac="${YEL}ᗧ${RST}"; else pac="${YEL}ᗤ${RST}"; fi + + # eaten section: yellow dots + local eaten="" + if (( filled > 0 )); then + eaten="${YEL}" + for (( i=0; i 0 )); then + local ghost_positions=() + if (( empty >= 6 )); then ghost_positions+=( $((empty / 3)) ); fi + if (( empty >= 12 )); then ghost_positions+=( $((empty * 2 / 3)) ); fi + + ahead="${DIM}" + for (( i=0; i&2 +} + +printf "${YEL}ᗧ··ᗤ${RST} ${WHT}dedupe${RST} ${DIM}v${VERSION}${RST}\n" >&2 +printf "${DIM} scanning...${RST}" >&2 +total_files=$(find . $depth -type f | wc -l | tr -d ' ') +printf "\r${YEL}ᗧ${RST} Hashing ${WHT}%d${RST} files...\n" "$total_files" >&2 + +count=0 +find . $depth -type f | while IFS= read -r file; do + count=$((count + 1)) + progress_bar "$count" "$total_files" + md5sum "$file" +done | sort | awk -v dry_run="${dry_run:-0}" ' BEGIN { first = 1; total = 0 } $1 != prev && prev != "" { @@ -68,3 +140,5 @@ END { else while IFS= read -r f; do rm -f "$f" 2>/dev/null; done fi + +printf "\n" >&2