69 lines
1.2 KiB
Bash
Executable File
69 lines
1.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
################################
|
|
# Shows info about a specified mount point
|
|
#
|
|
# Dependencies:
|
|
# - [notify-send]
|
|
#
|
|
# @param {String} disk: The mount point to check
|
|
# @return {Number(%)}: Space used on the disk
|
|
################################
|
|
|
|
dir=$(dirname $0)
|
|
source $dir/util.sh
|
|
|
|
full=""
|
|
short=""
|
|
status=0
|
|
|
|
disks=$(lsblk | tail -n +2 | awk '{ print $7 }' | sed '/^\s*$/d' | sort)
|
|
let numDisks=$(echo "$disks" | wc -l)
|
|
let diskNum=$(getCache 1)
|
|
|
|
getDisk() {
|
|
echo "$disks" | sed -n "$diskNum p"
|
|
}
|
|
disk=$(getDisk)
|
|
|
|
case $BLOCK_BUTTON in
|
|
# right click: show details
|
|
# TODO: fix
|
|
3)
|
|
local summary=$(du -h --max-depth=1 $disk)
|
|
notify-send "Disk usage" "$summary"
|
|
;;
|
|
# scroll up: cycle disks
|
|
4)
|
|
diskNum=$[$(getCache) - 1]
|
|
if (( diskNum <= 0 )); then
|
|
diskNum=$numDisks
|
|
fi
|
|
setCache $diskNum
|
|
disk=$(getDisk)
|
|
;;
|
|
5)
|
|
# scroll down: cycle disks
|
|
diskNum=$[$(getCache) + 1]
|
|
if (( diskNum >= numDisks + 1 )); then
|
|
diskNum=1
|
|
fi
|
|
setCache $diskNum
|
|
disk=$(getDisk)
|
|
;;
|
|
esac
|
|
|
|
usage=$(df -h $disk | sed -n '2 p')
|
|
usage=($usage)
|
|
|
|
if [ ${usage[4]%?} -ge 90 ]; then
|
|
status=33
|
|
fi
|
|
|
|
full="$disk ${usage[4]}"
|
|
short="$full"
|
|
|
|
echo $full
|
|
echo $short
|
|
exit $status
|