#!/bin/sh -e
#
#    disk-available: print the current disk space available
#    Copyright (C) 2008 Canonical Ltd.
#
#    Authors: Dustin Kirkland <kirkland@canonical.com>
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation, version 3 of the License.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.

PKG="byobu"

if [ "$1" = "--detail" ]; then
	df -h
	exit 0
fi

comma=
whitespace=
if [ -r "$HOME/.$PKG/status" ]; then
	grep -qs "^disk-used=1$" "$HOME/.$PKG/status" && comma="," || whitespace=" "
else
	comma=","
fi

# Default to /, but let users override
[ -r "$HOME/.$PKG/disk" ] && MP=`cat "$HOME/.$PKG/disk"` || MP="/"

d=`df -h "$MP" | tail -n 1 | awk '{print $2}'`
printf "\005{= MW}%sB%s\005{-}%s" "$d" "$comma" "$whitespace"
