summarylogtreecommitdiffstats
path: root/dfp
blob: 069751677cc335167c8b049b44c2711848dfd66e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash

DF="/usr/bin/df"

usage() {
	echo 'usage: dfp [-p PREFIX] DEVICE...'
	echo
	echo '  -p    print given prefix at the begin of each line'
	echo '  -h    display this help and exit'
	exit
}

while getopts ":hp:" optname; do
	case "$optname" in
		"p")
			prefix=$OPTARG
			;;
		"h")
			usage
			;;
		"?")
			echo "Unknown option $OPTARG"
			usage
			;;
		":")
			echo "No argument value for option $OPTARG"
			;;
		*)
			echo "Unknown error while processing options"
			;;
		esac
done

IFS=$"NUL"
declare -a args=${@:$OPTIND}
[[ ${args:0} ]] || args=$(df --output=target | tail --lines=+2 | tr "\n" $"NUL")

for device in $args; do
	if ! [[ "$($DF $device)" ]]; then
		usage
	fi
done

for device in $args; do
	size="$($DF $device --output=size | tail --lines=+2)"
	avail="$($DF $device --output=avail | tail --lines=+2)"
	used="$((size - avail))"
	
	availh="$($DF -h $device --output=avail | tail --lines=+2)"
	sizeh="$($DF -h $device --output=size | tail --lines=+2)"
	misc="$availh$sizeh"
	title="$prefix$device"

	pbar -n $used $size "$title" "$misc"
done