From d7cdc0e8dbd9f09ccedadbbe4ee959ce1efcc364 Mon Sep 17 00:00:00 2001 From: kai-waggeling Date: Fri, 4 Jul 2025 20:21:28 +0000 Subject: [PATCH] =?UTF-8?q?update-motd.d/30-disks=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- update-motd.d/30-disks | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 update-motd.d/30-disks diff --git a/ update-motd.d/30-disks b/ update-motd.d/30-disks new file mode 100644 index 0000000..5f13d25 --- /dev/null +++ b/ update-motd.d/30-disks @@ -0,0 +1,41 @@ +#!/bin/bash + +# config +max_usage=90 +bar_width=50 +# colors +white="\e[39m" +green="\e[1;32m" +red="\e[1;31m" +dim="\e[2m" +undim="\e[0m" + +# disk usage: ignore zfs, squashfs & tmpfs +mapfile -t dfs < <(df -H -x zfs -x squashfs -x tmpfs -x devtmpfs -x overlay --output=target,pcent,size | tail -n+2) +printf "\ndisk usage:\n" + +for line in "${dfs[@]}"; do + # get disk usage + usage=$(echo "$line" | awk '{print $2}' | sed 's/%//') + used_width=$((($usage*$bar_width)/100)) + # color is green if usage < max_usage, else red + if [ "${usage}" -ge "${max_usage}" ]; then + color=$red + else + color=$green + fi + # print green/red bar until used_width + bar="[${color}" + for ((i=0; i<$used_width; i++)); do + bar+="=" + done + # print dimmmed bar until end + bar+="${white}${dim}" + for ((i=$used_width; i<$bar_width; i++)); do + bar+="=" + done + bar+="${undim}]" + # print usage line & bar + echo "${line}" | awk '{ printf("%-31s%+3s used out of %+4s\n", $1, $2, $3); }' | sed -e 's/^/ /' + echo -e "${bar}" | sed -e 's/^/ /' +done \ No newline at end of file