Skip to content

Commit

Permalink
Disk Usage: show in a dimmed colour when available space is less than… (
Browse files Browse the repository at this point in the history
#1104)

* Disk Usage: show in a dimmed colour when available space is less than 2% of capacity.

* quote variables to fix lint error SC2206.

* more quoting to fix lint errors SC2206, SC2207.

* more quoting to fix lint errors SC2206, SC2207.
  • Loading branch information
sohocoke authored and tresni committed Dec 13, 2018
1 parent 330a450 commit 6e439a8
Showing 1 changed file with 29 additions and 16 deletions.
45 changes: 29 additions & 16 deletions System/mdf.1m.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ make_bmp_header() {
# Common bits for version 1 and 5
bmp_header+=(
42 4d # "BM" magic
$_filebytes # size of file
"$_filebytes" # size of file
00 00 # reserved
00 00 # reserved
$_pixoffset # offset of pixel data
$_headerbytes # remaining bytes in header
$_width # width
$_height # height
"$_pixoffset" # offset of pixel data
"$_headerbytes" # remaining bytes in header
"$_width" # width
"$_height" # height
01 00 # 1 color plane
20 00 # 32 bits per pixel
$comp 00 00 00 # compression
$_pixbytes # size of pixel data
"$comp" 00 00 00 # compression
"$_pixbytes" # size of pixel data
13 0b 00 00 # ~72 dpi horizontal
13 0b 00 00 # ~72 dpi vertical
00 00 00 00 # colors in palette
Expand Down Expand Up @@ -176,8 +176,8 @@ function rect() {
}

output_bmp() {
local _bmp=(${bmp_header[@]/#/'\x'})
_bmp+=(${pixels[@]/#/'\x'})
local _bmp=("${bmp_header[@]/#/'\x'}")
_bmp+=("${pixels[@]/#/'\x'}")

local IFS=''
#echo -ne "${_bmp[*]}" >/tmp/mtop.bmp
Expand All @@ -199,7 +199,7 @@ init_bmp() {
if [ ${#pixels[@]} -ne $pixbytes ]; then
pixels=()
for ((i = 0; i < width * height; i++)); do
pixels+=(${curcol[@]});
pixels+=("${curcol[@]}");
done
fi
}
Expand All @@ -212,6 +212,7 @@ osver=$(sw_vers -productVersion)

# Colors in BGRA format
fgcol=(00 00 00 ff)
fgcol_alert=(00 00 00 88) # semi-transparent.
bgcol=(00 00 00 00)
bmp_ver=5
icontype=templateImage
Expand All @@ -222,14 +223,26 @@ if [[ $osver == 10.8.* ]]; then
icontype=image
fi

# return the alert colour if alert condition is met.
# else return foreground colour.
# alert condition: free capacity < 2%.
determine_col() {
if (( $1 < 98 )); then
retval=("${fgcol[@]}")
else
retval=("${fgcol_alert[@]}")
fi
}

# Routines to draw simple progress-bar-like buckets for showing
# capacity of disks, batteries etc.

init_bar() {
pixels=()
curcol=(${bgcol[@]})
curcol=("${bgcol[@]}")
init_bmp $bmp_ver "$1" "$2"
curcol=(${fgcol[@]})
determine_col "$root_capacity"; col=("${retval[@]}")
curcol=("${col[@]}")
rect 0 0 "$1" "$2"
}

Expand Down Expand Up @@ -262,16 +275,16 @@ get_disk_stats() {
local IFS=$'\n'
local i dfdata dudata diskname

dfdata=($(df -H))
dfdata=("$(df -H)")

IFS=$OLDIFS
for ((i = 0; i < ${#dfdata[@]}; i++)); do
line=(${dfdata[$i]})
for ((i = 0; i < "${#dfdata[@]}"; i++)); do
line=("${dfdata[$i]}")
if [ "${line[8]}" = "/" ]; then
root_capacity="${line[4]/\%}"
fi
if [[ "${line[0]}" == /dev/* ]]; then
dudata=($(diskutil info "${line[0]}" | grep "Volume Name"))
dudata=("$(diskutil info "${line[0]}" | grep "Volume Name")")
diskname="${dudata[*]:2}"
disk+=("${diskname:-Untitled}")
used+=("${line[2]}")
Expand Down

0 comments on commit 6e439a8

Please sign in to comment.