From 5ff2649a797d130f276cfa41c29ca9977e6d4b49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20Ob=C5=AFrka?= Date: Sun, 23 Aug 2015 12:53:33 +0200 Subject: wpos: Make some pieces of code more generic --- wpos.sh | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/wpos.sh b/wpos.sh index 2695f15..1fecd4d 100755 --- a/wpos.sh +++ b/wpos.sh @@ -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 -- cgit v1.2.3