#!/usr/bin/env bash
# df-bar.sh: Simple disk usage bar chart (No Color, No Header)
# Characters: X = Used, - = Empty
# Excludes: tmpfs, efivarfs

BAR_WIDTH=20  # Total width of the bar in characters

# Optional: Print a custom simple header if desired, otherwise remove this line
# printf "%-15s %8s %5s %${BAR_WIDTH}s\n" "MOUNTPOINT" "SIZE" "USED" "BAR"

while read -r line; do
    # Extract fields: Size (2nd), Use% (5th), Mount (6th)
    # Note: df output columns might shift slightly if types are excluded, 
    # but standard 'df -h' usually keeps Use% at $5 and Mount at $6/NF.
    # Using NF for mount ensures we get the last column even if names vary.
    size=$(echo "$line" | awk '{print $2}')
    avail=$(echo "$line" | awk '{print $4}')
    usage=$(echo "$line" | awk '{print $5}' | tr -d '%')
    mount=$(echo "$line" | awk '{print $NF}')
    mount="${mount##*/}" 
    [[ -z $mount ]] && mount='/'
    
    # Calculate bar segments
    filled=$((usage * BAR_WIDTH / 100))
    empty=$((BAR_WIDTH - filled))
    
    # Generate bar strings
    bar_used=$(printf '%*s' "$filled" '' | sed 's/ /█/g')  #tr ' ' '█')
    bar_empty=$(printf '%*s' "$empty" '' | sed 's/ /░/g')  #tr ' ' '░')
    
    # Output: Mount | Size | %Used | Bar
    printf "%-10s [%4s /%5s] %5s%% %s%s\n" "$mount" "$size" "$avail" "$usage" "$bar_used" "$bar_empty"
    
done < <([[ $# = 0 ]] && df -h -x tmpfs -x efivarfs|grep -v sda1| tail -n +2 2>/dev/null || df -h -x tmpfs -x efivarfs | tail -n +2|grep -v sda)   
