fastu animator

This commit is contained in:
q
2018-10-20 13:45:04 +03:00
parent a97b387b54
commit 7711c4efae

View File

@@ -6,6 +6,7 @@ function helpexit() {
echo " -h Human readable units" echo " -h Human readable units"
echo " -s Summary mode, otherwise each argument folder calculated separate" echo " -s Summary mode, otherwise each argument folder calculated separate"
echo " -c Count files instead of summarizing sizes" echo " -c Count files instead of summarizing sizes"
echo " -a Display animation while counting"
echo " --help This help" echo " --help This help"
exit exit
} }
@@ -45,6 +46,15 @@ function siprefix() {
}' || return $? }' || return $?
} }
function animate() {
CHARS="|/-__-\\"
i=0
while true; do
sleep 0.2
printf "\r%s\r" ${CHARS:$i:1} >&2
i=$(( (i + 1)%${#CHARS} ))
done
}
function processfolder() { function processfolder() {
if [[ "$COUNT" -eq 1 ]]; then if [[ "$COUNT" -eq 1 ]]; then
@@ -77,12 +87,17 @@ for (( i=1; i<=$#; i++ )); do
[[ "${!i}" = "-h" ]] && { HUMAN=1; continue; } [[ "${!i}" = "-h" ]] && { HUMAN=1; continue; }
[[ "${!i}" = "-c" ]] && { COUNT=1; continue; } [[ "${!i}" = "-c" ]] && { COUNT=1; continue; }
[[ "${!i}" = "-s" ]] && { SUMMARY=1; continue; } [[ "${!i}" = "-s" ]] && { SUMMARY=1; continue; }
[[ "${!i}" = "-a" ]] && { ANIMATE=1; continue; }
what+=( "${!i}" ) what+=( "${!i}" )
done done
[[ -z "${what[@]}" ]] && what="." [[ -z "${what[@]}" ]] && what="."
# If only one entry, dont print the name # If only one entry, dont print the name
[[ "${#what[@]}" -eq 1 ]] && SUMMARY=1 [[ "${#what[@]}" -eq 1 ]] && SUMMARY=1
if [[ "$ANIMATE" -eq 1 ]]; then
animate &
fi
if [[ "$SUMMARY" -eq 1 ]]; then if [[ "$SUMMARY" -eq 1 ]]; then
# Display one line # Display one line
processfolder "${what[@]}" processfolder "${what[@]}"
@@ -97,4 +112,7 @@ else
printf "$FORMAT" "$( processfolder "$dir" )" "$dir" printf "$FORMAT" "$( processfolder "$dir" )" "$dir"
done done
fi fi
if [[ "$ANIMATE" -eq 1 ]]; then
kill %1
fi