mirror of
https://codeberg.org/frosty/dotfiles.git
synced 2024-09-19 19:57:08 -04:00
57 lines
1.1 KiB
Bash
Executable file
57 lines
1.1 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
LOW_USED_COLOR="#a3be8c"
|
|
MEDIUM_USED_COLOR="#ebcb8b"
|
|
HIGH_USED_COLOR="#bf616a"
|
|
DEFAULT_USED_COLOR="#81a1c1"
|
|
UNUSED_COLOR="#5e81ac"
|
|
|
|
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=$(printf 'scale=0; (%s * %s) / 100\n' "$usage" "$width" | 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
|
|
|
|
prev_opened=0
|
|
any_used_width=0
|
|
i=1
|
|
while [ "$i" -le "$width" ]; do
|
|
if [ "$i" -le "$num_used_chars" ]; then
|
|
if [ "$prev_opened" -eq 0 ]; then
|
|
bar="$bar<fc=$used_color>"
|
|
prev_opened=1
|
|
any_used_width=1
|
|
fi
|
|
bar="$bar#"
|
|
else
|
|
if [ "$any_used_width" -eq 1 ]; then
|
|
bar="$bar</fc>"
|
|
prev_opened=0
|
|
any_used_width=0
|
|
fi
|
|
if [ "$prev_opened" -eq 0 ]; then
|
|
bar="$bar<fc=$UNUSED_COLOR>"
|
|
prev_opened=1
|
|
fi
|
|
bar="$bar:"
|
|
fi
|
|
i=$((i + 1))
|
|
done
|
|
bar="$bar</fc>"
|
|
|
|
printf '%s\n' "$bar"
|