zsh: add pv-backed mv/cp wrappers with progress and dir creation

Override mv and cp to pipe large transfers through pv for progress.
Directories are streamed via tar+pv; single files go through pv
directly. Parent directories are created (mkdir -p) when the
destination path doesn't exist yet.
This commit is contained in:
2026-08-18 08:01:05 -06:00
parent 5cfa02ea6b
commit 21dbb16e8b
+59
View File
@@ -139,3 +139,62 @@ alias pip=pip3
. "/home/sammieo/.deno/env" . "/home/sammieo/.deno/env"
export LC_ALL="en_US.UTF-8" export LC_ALL="en_US.UTF-8"
# Make sure no alias hides the real mv / cp
unalias mv 2>/dev/null
unalias cp 2>/dev/null
# Custom 'move' command that incorporates the pv command
mv() {
if (( $# > 2 )); then
command mv "$@"
return
fi
local src=$1 dest=$2
if [ -d "$src" ]; then
mkdir -p "$dest"
# Total size in bytes (du -sb)
local total=$(du -sb "$src" | awk '{print $1}')
# Pipe through pv and extract at destination
tar -cf - -C "$(dirname "$src")" "$(basename "$src")" |
pv -s "$total" |
tar -xf - -C "$dest"
# Remove the original directory
rm -rf "$src"
else
mkdir -p "$(dirname "$dest")"
command mv "$@"
fi
}
# Custom 'cp' command that incorporates the pv command
cp() {
if (( $# > 2 )); then
command cp "$@"
return
fi
local src=$1 dst=$2
if [ -d "$src" ]; then
mkdir -p "$dst"
# ---- 1️⃣ Total size of the directory ---------------------------------
local total=$(du -sb "$src" | awk '{print $1}')
# ---- 2️⃣ Stream the dir through pv into the destination ---------------
tar -cf - -C "$(dirname "$src")" "$(basename "$src")" |
pv -s "$total" |
tar -xf - -C "$dst"
else
# ---- 3️⃣ Single file -------------------------------------------------
mkdir -p "$(dirname "$dst")"
local fsize=$(stat -c%s "$src" 2>/dev/null || wc -c <"$src")
pv -s "$fsize" < "$src" > "$dst"
fi
}