#!/bin/sh -e

__disk_detail() {
  if [ $(uname) = "FreeBSD" -o $(uname) = "Darwin" ]; then
    df -h
  else
    df -h -P
  fi
}

__disk() {
  local use="" total=""
  if [ $(uname) = "FreeBSD" ]; then
    use=$(zpool list | tail -1 | awk '{ print $3 }')
    total=$(zpool list | tail -1 | awk '{ print $2 }')
  elif [ $(uname) = "Darwin" ]; then
    free=$(diskutil info / | awk -F': ' '/Free Space/ {print $2}' | awk '{gsub(/[^0-9.]/, "", $1); print $1}')
    total=$(diskutil info / | awk -F': ' '/Total Space/ {print $2}' | awk '{gsub(/[^0-9.]/, "", $1); print $1}')
    funit=$(diskutil info / | grep "Free Space" | awk '{print $5}' | sed 's/B//')
    tunit=$(diskutil info / | grep "Total Space" | awk '{print $5}' | sed 's/B//')
    use=$(echo "$total - $free" | bc)
    use=$(echo "$use $funit")
    total=$(echo "$total $tunit")
  else
    use=$(df -h "/" | tail -1 | awk '{ print $3 }')
    total=$(df -h "/" | tail -1 | awk '{ print $2 }')
  fi
  color b m W; printf "%s%s/" "$use" "iB"; color -; color b m W; printf "%s%s" "$total" "iB"; color --;
}

# vi: syntax=sh ts=4 noexpandtab