Skip to content

Commit

Permalink
Convert to bash.
Browse files Browse the repository at this point in the history
  • Loading branch information
calvertdw committed Nov 23, 2024
1 parent 17951dc commit bc1dcd3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 37 deletions.
37 changes: 0 additions & 37 deletions .tools/list-lfs-by-size.py

This file was deleted.

29 changes: 29 additions & 0 deletions .tools/list_lfs_by_size.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# Function to convert human-readable sizes to bytes
size_to_bytes() {
local size=$(echo $1 | cut -d' ' -f1)
local unit=$(echo $1 | cut -d' ' -f2)
size=${size%.*} # Remove decimal part
case $unit in
KB) echo $((size * 1024)) ;;
MB) echo $((size * 1024 * 1024)) ;;
GB) echo $((size * 1024 * 1024 * 1024)) ;;
*) echo $size ;;
esac
}

# Get LFS files, convert sizes to bytes, sort, and print
git lfs ls-files -s |
while IFS= read -r line; do
if [[ $line =~ (.*)\((.*)\)$ ]]; then
file_path="${BASH_REMATCH[1]}"
size_str="${BASH_REMATCH[2]}"
size_bytes=$(size_to_bytes "$size_str")
printf "%020d|%s|%s\n" "$size_bytes" "$file_path" "$size_str"
fi
done |
sort -r |
while IFS='|' read -r size_bytes file_path size_str; do
echo "${file_path}(${size_str})"
done

0 comments on commit bc1dcd3

Please sign in to comment.