Skip to content

Instantly share code, notes, and snippets.

@Ogromny
Created August 5, 2022 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ogromny/bd8d22828fdcf0879ad181f1dbfcee28 to your computer and use it in GitHub Desktop.
Save Ogromny/bd8d22828fdcf0879ad181f1dbfcee28 to your computer and use it in GitHub Desktop.
#!/bin/sh
temp_file="$(mktemp)"
unit_file="$(mktemp)"
kiss list | cut -d" " -f1 > "$temp_file"
cat > "$unit_file" <<EOF
KB
MB
GB
EOF
log() {
printf "\033[0;32m[%s]\033[0m %s\n" "$1" "$2"
}
err() {
printf "\033[0;31m%s\033[0m: %s\n" "$1" "$2"
}
while read -r var; do
eval $(echo ${var}S="")
done < "$unit_file"
printf "\033[s"
while IFS="" read -r package; do
printf "Checking \033[1;32m\"$package\"\033[0m"
size="$(kiss size "$package" 2>&1 | tail -n1 | cut -d" " -f1)"
matched=0
while read -r var; do
case "$size" in
*$var)
eval "$(echo ${var}S)=\";$package $size$(eval echo \$$(echo ${var}S))\""
matched=1
;;
esac
[ "$matched" = 1 ] && break
done < "$unit_file"
[ "$matched" = 0 ] && {
err "Unknown unit" "$size"
exit 1
}
printf "\033[1K\033[u"
done < "$temp_file"
>"$temp_file"
while read -r var; do
echo $(eval echo \${$(echo ${var}S):1}) | tr ";" "\n" | sort -n -k2 -t" " |
while read -r package size; do
log "$package" "$size" >> "$temp_file"
done
done < "$unit_file"
tac "$temp_file"
rm "$temp_file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment