summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Robin Obůrka <r.oburka@gmail.com> 2015-02-26 11:46:52 +0100
committerGravatar Robin Obůrka <r.oburka@gmail.com> 2015-02-26 11:46:52 +0100
commit0f4c5b5417bba1e99108c46a5a1e35a77b8c89a1 (patch)
tree024149282e85d9314da0c7ca5c9c5e31c7e88d67
parentFix rexexp in detect_status (diff)
downloaddisplay_autoset-0f4c5b5417bba1e99108c46a5a1e35a77b8c89a1.tar.xz
Fix resolution parser and move it to function
-rwxr-xr-xautodetect.sh9
1 files 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