From: Austin Glaser Date: Tue, 30 Aug 2016 04:48:32 +0000 (-0600) Subject: Allow 40autorandr to handle any order fields from loginctl X-Git-Tag: 1.0~15^2 X-Git-Url: https://git.donarmstrong.com/?p=deb_pkgs%2Fautorandr.git;a=commitdiff_plain;h=8467e92bd5d04acbfc263e25bf55a71082df7b15 Allow 40autorandr to handle any order fields from loginctl This could be done a great deal more cleanly using bash regex matching; however, as is stated elsewhere, the script will not always be executed with bash. There may be some merit to causing the script to always be executed with bash (`#! /bin/bash` or even `#! /usr/bin/env bash`), but I'll admit I don't know how widely installed bash is. I've certainly never found a modern Linux install without bash, but my experience isn't the widest. --- diff --git a/contrib/pm-utils/40autorandr b/contrib/pm-utils/40autorandr index 0e029af..716f771 100755 --- a/contrib/pm-utils/40autorandr +++ b/contrib/pm-utils/40autorandr @@ -18,20 +18,28 @@ find_user() { # by SO user intelfx user="$( loginctl list-sessions --no-legend | while read id uid user seat; do - loginctl show-session -p Display -p Active "$id" | while IFS='=' read property value; do - case "$property" in - Active) - if [ "$value" != "yes" ]; then - continue - fi - ;; - Display) - if [ -n "$value" -a "$value" = "$D" ]; then - echo $user - fi - ;; - esac - done + session=$(loginctl show-session -p Display -p Active "$id") + first=$(echo $session | cut -d" " -f1) + second=$(echo $session | cut -d" " -f2) + + if [ -n $(echo "$first" | grep "Display") ]; then + display=$first + active=$second + else + display=$second + active=$first + fi + + active_value=$(echo "$active" | cut -d"=" -f2) + display_value=$(echo "$display" | cut -d"=" -f2) + + if [ "$active_value" != "yes" ]; then + continue + fi + + if [ -n $display_value -a "$display_value" = "$D" ]; then + echo $user + fi done )" if [ -n "$user" ]; then