#!/bin/sh LOW_USED_COLOR="#b8bb26" MEDIUM_USED_COLOR="#fabd2f" HIGH_USED_COLOR="#fb4934" DEFAULT_USED_COLOR="#d5c4a1" UNUSED_COLOR="#a88984" usage=$1 width=$2 usage_color=$3 command -v "$1" >/dev/null && usage=$($1) low_used=$((width * 30 / 100)) medium_used=$((width * 60 / 100)) num_used_chars=$(echo "scale=0; ($usage * $width) / 100" | bc -l) if [ -n "$usage_color" ]; then case "$num_used_chars" in [0-$low_used]) used_color="$LOW_USED_COLOR" ;; [$low_used-$medium_used]) used_color="$MEDIUM_USED_COLOR" ;; *) used_color="$HIGH_USED_COLOR" ;; esac else used_color="$DEFAULT_USED_COLOR" fi i=1 while [ "$i" -le "$width" ]; do if [ "$i" -le "$num_used_chars" ]; then bar="$bar#" else bar="$bar:" fi i=$((i + 1)) done echo "$bar"