#!/usr/bin/bash 
#
# disks: Simple disk usage bar chart (No Color, No Header)
# 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}')
    used=$(echo "$line" | awk '{print $3}')
    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
    if [[ $# = 0 ]] 
    then
        [[ $mount = *"laptop"* ]] && ICON="⏏️ " || ICON="💽" 
        BAR="$(tput setaf 2; tput bold)" 
        [[ $(echo $usage | tr -d '%') -gt 75 ]] && BAR="$(tput setaf 3; tput bold)"
        [[ $(echo $usage | tr -d '%') -gt 90 ]] && BAR="$(tput setaf 1; tput bold)" 
        printf "$ICON $(tput setaf 2; tput bold)%-10s$(tput setaf 6; tput bold) [%4s /%5s]$(tput sgr0) %5s%%${BAR} %s%s\n" "$mount" "$used" "$size" "$usage" "$bar_used" "$bar_empty"
    else
        printf "%-10s [%4s /%5s] %5s%% %s%s\n" "$mount" "$used" "$size" "$usage" "$bar_used" "$bar_empty"
    fi
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)   

if [[ $# = 0 ]] 
then
    Xi="$(lsusb | grep -i "Xiaomi" |cut -d' ' -f1,7- | sed -e 's/Bus/📱/g')"
    Qu="$(lsusb | grep -i "Qualcomm" |cut -d' ' -f1,7- | sed -e 's/Bus/📱/g')"
    [[ -n $Xi ]] && echo "$Xi --|Charging|--"
    [[ -n $Qu ]] && echo "$Qu --|Charging|--"
else
    Xi="$(lsusb | grep -i "Xiaomi" |cut -d' ' -f7-)"
    Qu="$(lsusb | grep -i "Qualcomm" |cut -d' ' -f7-)"
    [[ -n $Xi ]] && echo "$Xi --|Charging|--"
    [[ -n $Qu ]] && echo "$Qu --|Charging|--"
fi

