From 0f4c5b5417bba1e99108c46a5a1e35a77b8c89a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20Ob=C5=AFrka?= Date: Thu, 26 Feb 2015 11:46:52 +0100 Subject: Fix resolution parser and move it to function --- autodetect.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/autodetect.sh b/autodetect.sh index a6aec2e..9c11e85 100755 --- a/autodetect.sh +++ b/autodetect.sh @@ -17,6 +17,9 @@ EXT2_STATUS="disconnected" XRANDR="$(xrandr -q)" ## Some functions +get_resolution() { + grep -A1 "^$1\s*connected" | tail -n1 | awk '{print $1 }' +} detect_status() { echo "$XRANDR" | sed -n -e "s/^$1\s*\([a-z]*\)\s*.*$/\1/p" } @@ -54,9 +57,9 @@ if [ -n "$EXT1_NAME" ]; then EXT2_NAME="$(echo "$XRANDR" | grep -v "\($NOTE_NAME\|$EXT1_NAME\)" | detect_connected | head -n 1)" [ -n "$EXT2_NAME" ] && EXT2_STATUS="$(detect_status "$EXT2_NAME")" fi -NOTE_MAX=$(echo "$XRANDR" | grep -A 1 "$NOTE_NAME" | tail -n1 | awk '{ print $1 }') -EXT1_MAX=$(echo "$XRANDR" | grep -A 1 "$EXT1_NAME" | tail -n1 | awk '{ print $1 }') -EXT2_MAX=$(echo "$XRANDR" | grep -A 1 "$EXT2_NAME" | tail -n1 | awk '{ print $1 }') +NOTE_MAX="$(echo "$XRANDR" | get_resolution "$NOTE_NAME")" +EXT1_MAX="$(echo "$XRANDR" | get_resolution "$EXT1_NAME")" +EXT2_MAX="$(echo "$XRANDR" | get_resolution "$EXT2_NAME")" ## Main "profiles" logic if [ "$COMMAND" = "external" -a "$EXT1_STATUS" = "connected" ]; then -- cgit v1.2.3