fastdu support sorting better
This commit is contained in:
36
files/fastdu
36
files/fastdu
@@ -16,7 +16,7 @@ function filesize() {
|
|||||||
# Usage: filesize 10000
|
# Usage: filesize 10000
|
||||||
|
|
||||||
[ "$1" = "0" ] && {
|
[ "$1" = "0" ] && {
|
||||||
echo "0 B"
|
echo "0~B"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -24,8 +24,8 @@ function filesize() {
|
|||||||
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--)
|
for(i=7;y < 1;i--)
|
||||||
y = x / (2^(10*i))
|
y = x / (2^(10*i))
|
||||||
str=int(y*10)/10 " " type[i+2]
|
str=int(y*10)/10 type[i+2]
|
||||||
if (i==-1) { str = x " B" }
|
if (i==-1) { str = x "~B" }
|
||||||
print str
|
print str
|
||||||
}' || return $?
|
}' || return $?
|
||||||
}
|
}
|
||||||
@@ -33,7 +33,7 @@ function siprefix() {
|
|||||||
# Return a SI prefixed string from integer
|
# Return a SI prefixed string from integer
|
||||||
|
|
||||||
[ "$1" = "0" ] && {
|
[ "$1" = "0" ] && {
|
||||||
echo "0 #"
|
echo "0~#"
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,8 +41,8 @@ function siprefix() {
|
|||||||
split("# k# M# G# T# P# E# Z#",type)
|
split("# k# M# G# T# P# E# Z#",type)
|
||||||
for(i=7;y < 1;i--)
|
for(i=7;y < 1;i--)
|
||||||
y = x / (10^(3*i))
|
y = x / (10^(3*i))
|
||||||
str=int(y*10)/10 " " type[i+2]
|
str=int(y*10)/10 type[i+2]
|
||||||
if (i==-1) { str = x " #" }
|
if (i==-1) { str = x "~#" }
|
||||||
print str
|
print str
|
||||||
}' || return $?
|
}' || return $?
|
||||||
}
|
}
|
||||||
@@ -74,15 +74,22 @@ function processfolder() {
|
|||||||
echo -e "$SIZE\t$COUNTS"
|
echo -e "$SIZE\t$COUNTS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function formatter() {
|
||||||
|
cat - | xargs printf "$FORMAT" | sed -e 's,~B, B,' -e 's,~#, #,'
|
||||||
|
}
|
||||||
# Get options
|
# Get options
|
||||||
what=()
|
what=()
|
||||||
for (( i=1; i<=$#; i++ )); do
|
for (( i=1; i<=$#; i++ )); do
|
||||||
[[ "${!i}" = "-a" ]] && { ANIMATE=1; continue; }
|
|
||||||
[[ "${!i}" = "-f" ]] && { FORMAT=1; ((i++)); FORMAT_VALUE=${!i}; continue; }
|
[[ "${!i}" = "-f" ]] && { FORMAT=1; ((i++)); FORMAT_VALUE=${!i}; continue; }
|
||||||
[[ "${!i}" = "--help" ]] && helpexit
|
[[ "${!i}" = "--help" ]] && helpexit
|
||||||
[[ "${!i}" = "-h" ]] && { HUMAN=1; continue; }
|
|
||||||
[[ "${!i}" = "-c" ]] && { COUNT=1; continue; }
|
[[ "${!i}" = "-"* ]] && {
|
||||||
[[ "${!i}" = "-s" ]] && { SUMMARY=1; continue; }
|
[[ "${!i}" =~ -.*a ]] && { ANIMATE=1; }
|
||||||
|
[[ "${!i}" =~ -.*h ]] && { HUMAN=1; }
|
||||||
|
[[ "${!i}" =~ -.*c ]] && { COUNT=1; }
|
||||||
|
[[ "${!i}" =~ -.*s ]] && { SUMMARY=1; }
|
||||||
|
continue
|
||||||
|
}
|
||||||
what+=( "${!i}" )
|
what+=( "${!i}" )
|
||||||
done
|
done
|
||||||
|
|
||||||
@@ -93,7 +100,7 @@ if [[ "$FORMAT" -eq 1 ]]; then
|
|||||||
echo -e "\nBytes argument missing\n\n"
|
echo -e "\nBytes argument missing\n\n"
|
||||||
helpexit
|
helpexit
|
||||||
fi
|
fi
|
||||||
filesize $FORMAT_VALUE
|
filesize $FORMAT_VALUE | sed 's,~B, B,'
|
||||||
exit $?
|
exit $?
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -103,7 +110,7 @@ fi
|
|||||||
if [[ "$ANIMATE" -eq 1 ]]; then
|
if [[ "$ANIMATE" -eq 1 ]]; then
|
||||||
animate &
|
animate &
|
||||||
fi
|
fi
|
||||||
[[ "$HUMAN" -eq 1 ]] && NUMFORMAT="%5s %2s "
|
[[ "$HUMAN" -eq 1 ]] && NUMFORMAT="%7s "
|
||||||
[[ "$HUMAN" -ne 1 ]] && NUMFORMAT="%d\t"
|
[[ "$HUMAN" -ne 1 ]] && NUMFORMAT="%d\t"
|
||||||
[[ "$COUNT" -eq 1 ]] && NUMBERS="$NUMFORMAT$NUMFORMAT"
|
[[ "$COUNT" -eq 1 ]] && NUMBERS="$NUMFORMAT$NUMFORMAT"
|
||||||
[[ "$COUNT" -ne 1 ]] && NUMBERS="$NUMFORMAT"
|
[[ "$COUNT" -ne 1 ]] && NUMBERS="$NUMFORMAT"
|
||||||
@@ -113,12 +120,11 @@ fi
|
|||||||
|
|
||||||
if [[ "$SUMMARY" -eq 1 ]]; then
|
if [[ "$SUMMARY" -eq 1 ]]; then
|
||||||
# Display one line
|
# Display one line
|
||||||
processfolder "${what[@]}" | xargs printf "$FORMAT"
|
processfolder "${what[@]}" | formatter
|
||||||
echo ''
|
|
||||||
else
|
else
|
||||||
# One size for each argument
|
# One size for each argument
|
||||||
for ((i=0; i<"${#what[@]}"; i++)); do
|
for ((i=0; i<"${#what[@]}"; i++)); do
|
||||||
processfolder "${what[$i]}" | xargs printf "$FORMAT"
|
processfolder "${what[$i]}" | formatter
|
||||||
echo "${what[$i]}"
|
echo "${what[$i]}"
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ _build() {
|
|||||||
echo Target folder not an mdsite folder, delete first
|
echo Target folder not an mdsite folder, delete first
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
rsync -r --del "$1"/ "$2"
|
rsync -r "$1"/ "$2"
|
||||||
touch "$2"/.mdsite
|
touch "$2"/.mdsite
|
||||||
echo "----"
|
echo "----"
|
||||||
shopt -s nullglob
|
shopt -s nullglob
|
||||||
|
|||||||
Reference in New Issue
Block a user