BrodieRobertson/scripts

Alternative to 'i3disk' Method

terminalforlife opened this issue · 0 comments

I thought you might be interested in this:

#!/usr/bin/env bash

read -a ARRAY <<< `df -h -l --output=pcent /home`
VALUE="${ARRAY[1]%\%}"
if [ $VALUE -gt 90 ]; then
        printf "\e[1;31m%s%%\e[0m\n" "$VALUE"
else
        printf "%s%%\n" "$VALUE"
fi

It saves the need for and loading up of awk, which I believe is a lot faster (good for polling) but the caveat is that it needs bash, whereas your previous script uses sh. If you're okay with that.

However, this works differently, as I thought I'd offer something slightly different, in that this will instead turn red when the percentile hits and exceeds 90%. On that note, this will show the percentage of space used on the provided device. The previous behavior shouldn't be a problem to replicate, though.

Less parsing is needed too, since df is specifying to only display one field (plus header, sadly).

The code here is more of a proof of concept, by the way; I realise it might be missing some stuff you'd otherwise have.