progress bars
This commit is contained in:
78
dedupe
78
dedupe
@@ -1,4 +1,5 @@
|
|||||||
#!/bin/sh
|
#!/bin/bash
|
||||||
|
VERSION=$(date -r "$0" '+%Y-%m-%d')
|
||||||
depth="-maxdepth 1"
|
depth="-maxdepth 1"
|
||||||
dry_run=""
|
dry_run=""
|
||||||
|
|
||||||
@@ -20,7 +21,78 @@ while [ $# -gt 0 ]; do
|
|||||||
shift
|
shift
|
||||||
done
|
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<filled; i++ )); do eaten+="·"; done
|
||||||
|
eaten+="${RST}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# uneaten section: dim dots with ghosts sprinkled in
|
||||||
|
local ahead=""
|
||||||
|
if (( empty > 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<empty; i++ )); do
|
||||||
|
local is_ghost=0
|
||||||
|
for gp in "${ghost_positions[@]}"; do
|
||||||
|
if (( i == gp )); then is_ghost=1; break; fi
|
||||||
|
done
|
||||||
|
if (( is_ghost )); then
|
||||||
|
ahead+="${RST}${CYN}ᗣ${RST}${DIM}"
|
||||||
|
else
|
||||||
|
ahead+="·"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
ahead+="${RST}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf "\r %s%s%s ${WHT}%3d%%${RST} ${DIM}(%d/%d)${RST}" \
|
||||||
|
"$eaten" "$pac" "$ahead" "$pct" "$current" "$total" >&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 }
|
BEGIN { first = 1; total = 0 }
|
||||||
|
|
||||||
$1 != prev && prev != "" {
|
$1 != prev && prev != "" {
|
||||||
@@ -68,3 +140,5 @@ END {
|
|||||||
else
|
else
|
||||||
while IFS= read -r f; do rm -f "$f" 2>/dev/null; done
|
while IFS= read -r f; do rm -f "$f" 2>/dev/null; done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
printf "\n" >&2
|
||||||
|
|||||||
Reference in New Issue
Block a user