summaryrefslogtreecommitdiffstats
path: root/autodetect.sh
diff options
context:
space:
mode:
Diffstat (limited to 'autodetect.sh')
-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