fastdu support sorting better

This commit is contained in:
ville rantanen
2018-11-23 14:50:12 +02:00
parent 1e1c840fab
commit ab96989293
2 changed files with 23 additions and 17 deletions

View File

@@ -16,16 +16,16 @@ function filesize() {
# Usage: filesize 10000
[ "$1" = "0" ] && {
echo "0 B"
echo "0~B"
return 0
}
awk 'BEGIN{ x = '$1'
split("B kB MB GB TB PB EB ZB",type)
split("B kB MB GB TB PB EB ZB", type)
for(i=7;y < 1;i--)
y = x / (2^(10*i))
str=int(y*10)/10 " " type[i+2]
if (i==-1) { str = x " B" }
str=int(y*10)/10 type[i+2]
if (i==-1) { str = x "~B" }
print str
}' || return $?
}
@@ -33,7 +33,7 @@ function siprefix() {
# Return a SI prefixed string from integer
[ "$1" = "0" ] && {
echo "0 #"
echo "0~#"
return 0
}
@@ -41,8 +41,8 @@ function siprefix() {
split("# k# M# G# T# P# E# Z#",type)
for(i=7;y < 1;i--)
y = x / (10^(3*i))
str=int(y*10)/10 " " type[i+2]
if (i==-1) { str = x " #" }
str=int(y*10)/10 type[i+2]
if (i==-1) { str = x "~#" }
print str
}' || return $?
}
@@ -74,15 +74,22 @@ function processfolder() {
echo -e "$SIZE\t$COUNTS"
}
function formatter() {
cat - | xargs printf "$FORMAT" | sed -e 's,~B, B,' -e 's,~#, #,'
}
# Get options
what=()
for (( i=1; i<=$#; i++ )); do
[[ "${!i}" = "-a" ]] && { ANIMATE=1; continue; }
[[ "${!i}" = "-f" ]] && { FORMAT=1; ((i++)); FORMAT_VALUE=${!i}; continue; }
[[ "${!i}" = "--help" ]] && helpexit
[[ "${!i}" = "-h" ]] && { HUMAN=1; continue; }
[[ "${!i}" = "-c" ]] && { COUNT=1; continue; }
[[ "${!i}" = "-s" ]] && { SUMMARY=1; continue; }
[[ "${!i}" = "-"* ]] && {
[[ "${!i}" =~ -.*a ]] && { ANIMATE=1; }
[[ "${!i}" =~ -.*h ]] && { HUMAN=1; }
[[ "${!i}" =~ -.*c ]] && { COUNT=1; }
[[ "${!i}" =~ -.*s ]] && { SUMMARY=1; }
continue
}
what+=( "${!i}" )
done
@@ -93,7 +100,7 @@ if [[ "$FORMAT" -eq 1 ]]; then
echo -e "\nBytes argument missing\n\n"
helpexit
fi
filesize $FORMAT_VALUE
filesize $FORMAT_VALUE | sed 's,~B, B,'
exit $?
fi
@@ -103,7 +110,7 @@ fi
if [[ "$ANIMATE" -eq 1 ]]; then
animate &
fi
[[ "$HUMAN" -eq 1 ]] && NUMFORMAT="%5s %2s "
[[ "$HUMAN" -eq 1 ]] && NUMFORMAT="%7s "
[[ "$HUMAN" -ne 1 ]] && NUMFORMAT="%d\t"
[[ "$COUNT" -eq 1 ]] && NUMBERS="$NUMFORMAT$NUMFORMAT"
[[ "$COUNT" -ne 1 ]] && NUMBERS="$NUMFORMAT"
@@ -113,12 +120,11 @@ fi
if [[ "$SUMMARY" -eq 1 ]]; then
# Display one line
processfolder "${what[@]}" | xargs printf "$FORMAT"
echo ''
processfolder "${what[@]}" | formatter
else
# One size for each argument
for ((i=0; i<"${#what[@]}"; i++)); do
processfolder "${what[$i]}" | xargs printf "$FORMAT"
processfolder "${what[$i]}" | formatter
echo "${what[$i]}"
done
fi

View File

@@ -52,7 +52,7 @@ _build() {
echo Target folder not an mdsite folder, delete first
exit 1
fi
rsync -r --del "$1"/ "$2"
rsync -r "$1"/ "$2"
touch "$2"/.mdsite
echo "----"
shopt -s nullglob