diff options
author | Robin Obůrka <r.oburka@gmail.com> | 2015-08-23 12:53:33 +0200 |
---|---|---|
committer | Robin Obůrka <r.oburka@gmail.com> | 2015-08-23 12:53:33 +0200 |
commit | 5ff2649a797d130f276cfa41c29ca9977e6d4b49 (patch) | |
tree | a83994bb613c66772fc3f6402c21b48ccbb33f00 | |
parent | Add 2displays command (diff) | |
download | display_autoset-5ff2649a797d130f276cfa41c29ca9977e6d4b49.tar.xz |
wpos: Make some pieces of code more generic
-rwxr-xr-x | wpos.sh | 23 |
1 files changed, 16 insertions, 7 deletions
@@ -15,19 +15,28 @@ if [ -n "$2" ]; then PROFILE="$2" fi +query() { + wmctrl -lxG +} + +parse() { + LINE="$1" + ID="$(echo "$LINE" | awk '{ print $1 }')" + GRAVITY="$(echo "$LINE" | awk '{ print $2 }')" + POSX="$(echo "$LINE" | awk '{ print $3 }')" + POSY="$(echo "$LINE" | awk '{ print $4 }')" + WIDTH="$(echo "$LINE" | awk '{ print $5 }')" + HEIGHT="$(echo "$LINE" | awk '{ print $6 }')" +} + if [ "$1" = "save" ]; then - wmctrl -lxG > "$SAVEPATH/$PROFILE" + query > "$SAVEPATH/$PROFILE" exit 0 elif [ "$1" = "restore" ]; then cat "$SAVEPATH/$PROFILE" | while read LINE; do ## Parse records in savefile - ID="$(echo "$LINE" | awk '{ print $1 }')" - GRAVITY="$(echo "$LINE" | awk '{ print $2 }')" - POSX="$(echo "$LINE" | awk '{ print $3 }')" - POSY="$(echo "$LINE" | awk '{ print $4 }')" - WIDTH="$(echo "$LINE" | awk '{ print $5 }')" - HEIGHT="$(echo "$LINE" | awk '{ print $6 }')" + parse "$LINE" ## Check few important values [ "$GRAVITY" -lt 0 ] && continue |