UNIX Philosophy #1

A couple days ago I wrote a program for plotting in the terminal using braille characters.

Today I was bored and wanted to make a "minimap" of my desktop.

#!/bin/sh

[ $# -ne 2 ] && {
    echo 'usage: ' "$0 <cols> <rows>" 1>&2
    echo ' example; ' "$0 " '$COLUMNS' '$LINES' 1>&2
    exit 1
}

ROOT_X="`wattr x $(lsw -r)`"
ROOT_Y="`wattr y $(lsw -r)`"

[ $ROOT_X -eq 0 -o $ROOT_Y -eq 0 ] && ROOT_X=1280 ROOT_Y=800

TERM_X="$(($COLUMNS * 2))"
TERM_Y="$(($LINES * 4))"

lsw | while read WID
do
    read X Y W H << EOF
    `wattr xywh $WID`
EOF
    MAP_X1="$(($TERM_X*$X/$ROOT_X+1))"
    MAP_X2="$(($TERM_X*($X+$W)/$ROOT_X+1))"
    MAP_Y1="$(($TERM_Y*$Y/$ROOT_Y+1))"
    MAP_Y2="$(($TERM_Y*($Y+$H)/$ROOT_Y+1))"

    echo $MAP_X1 $MAP_Y1 to $MAP_X1 $MAP_Y2
    echo $MAP_X2 $MAP_Y2 to $MAP_X2 $MAP_Y1
    echo $MAP_X2 $MAP_Y1 to $MAP_X1 $MAP_Y1
    echo $MAP_X1 $MAP_Y2 to $MAP_X2 $MAP_Y2
done

This code is untested, ping me on IRC if it doesn't work for you.