From 9d1378c71c757187cd907565966fda8d0ae38aee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20Ob=C5=AFrka?= Date: Fri, 27 Mar 2015 19:21:51 +0100 Subject: Move computing hash to function --- autodetect.sh | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/autodetect.sh b/autodetect.sh index 651ecf4..8ed8efb 100755 --- a/autodetect.sh +++ b/autodetect.sh @@ -57,6 +57,22 @@ handle_non_exist_mode() { xrandr --dpi "$DPI" $(off_except "$1" "$2") --output $2 --mode $4 --output $1 --mode $3 --left-of $2 } +compute_hash() { + INPUT="$1" + + NOTE_ACTIVE="$(echo "$INPUT" | detect_active "$NOTE_NAME")" + HASH_DATA="${NOTE_NAME}${NOTE_STATUS}${NOTE_MAX}${NOTE_ACTIVE}" + if [ -n "$EXT1_NAME" ]; then + EXT1_ACTIVE="$(echo "$INPUT" | detect_active "$EXT1_NAME")" + HASH_DATA="${HASH_DATA}${EXT1_NAME}${EXT1_STATUS}${EXT1_MAX}${EXT1_ACTIVE}" + fi + if [ -n "$EXT2_NAME" ]; then + EXT2_ACTIVE="$(echo "$INPUT" | detect_active "$EXT2_NAME")" + HASH_DATA="${HASH_DATA}${EXT2_NAME}${EXT2_STATUS}${EXT2_MAX}${EXT2_ACTIVE}" + fi + echo "$HASH_DATA" | sha1sum | awk '{ print $1 }' +} + ## Get notebook display status NOTE_STATUS="$(echo "$XRANDR" | detect_status "$NOTE_NAME")" @@ -123,19 +139,7 @@ fi ## Query current status XRANDR="$(xrandr -q)" - -## Compute HASH of this profile -NOTE_ACTIVE="$(echo "$XRANDR" | detect_active "$NOTE_NAME")" -HASH_DATA="${NOTE_NAME}${NOTE_STATUS}${NOTE_MAX}${NOTE_ACTIVE}" -if [ -n "$EXT1_NAME" ]; then - EXT1_ACTIVE="$(echo "$XRANDR" | detect_active "$EXT1_NAME")" - HASH_DATA="${HASH_DATA}${EXT1_NAME}${EXT1_STATUS}${EXT1_MAX}${EXT1_ACTIVE}" -fi -if [ -n "$EXT2_NAME" ]; then - EXT2_ACTIVE="$(echo "$XRANDR" | detect_active "$EXT2_NAME")" - HASH_DATA="${HASH_DATA}${EXT2_NAME}${EXT2_STATUS}${EXT2_MAX}${EXT2_ACTIVE}" -fi -HASH="$(echo "$HASH_DATA" | sha1sum | awk '{ print $1 }')" +HASH="$(compute_hash "$XRANDR")" ## Update LAST echo "$HASH" > "$SAVEPATH"/"$LAST_FILE" -- cgit v1.2.3