the_earnest/dotfiles

bashrc, function r: invoke stat and rm separately for each file,

Commit 515e5f66b878 · The Earnest · 2026-11-24 14:29 +0000

Changeset
515e5f66b8782ef23def8bdabb077337bbdbd9a7

View source at this commit

bashrc, function r: invoke stat and rm separately for each file,
display size before deleting

Comments

No comments yet.

Log in to comment

Diff

diff --git a/bashrc b/bashrc
--- a/bashrc
+++ b/bashrc
@@ -194,8 +194,18 @@
 }
 
 function r() {
-	stat -c "%s %n" "$@"
-	rm -vi "$@" 
+	local size
+	local sizeh
+	for f in "$@"; do
+		if [[ ! -f "$f" ]]; then
+			echo "r: cannot remove '$f', no such file, skipping"
+			continue
+		fi
+		size=$(stat -c "%s" "$f")
+		sizeh=$(numfmt --to iec "$size")
+		echo -n "$sizeh, "
+		rm -vi "$f" 
+	done
 }
 
 function safermdir()