diff options
Diffstat (limited to 'autodetect.sh')
-rwxr-xr-x | autodetect.sh | 28 |
1 files changed, 6 insertions, 22 deletions
diff --git a/autodetect.sh b/autodetect.sh index 04da869..6f13330 100755 --- a/autodetect.sh +++ b/autodetect.sh @@ -18,9 +18,6 @@ EXT2_NAME="none" EXT1_STATUS="disconnected" EXT2_STATUS="disconnected" -## Query current settings -XRANDR="$(xrandr -q)" - ## Some functions get_resolution() { grep -A1 "^$1\\s*connected" | tail -n1 | awk '{ print $1 }' @@ -58,21 +55,13 @@ handle_non_exist_mode() { } 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 }' + echo "$1" | sha1sum | cut -d' ' -f1 } +## Query current settings +XRANDR="$(xrandr -q)" +HASH="$(compute_hash "$XRANDR")" + ## Get notebook display status NOTE_STATUS="$(echo "$XRANDR" | detect_status "$NOTE_NAME")" @@ -89,9 +78,7 @@ EXT2_MAX="$(echo "$XRANDR" | get_resolution "$EXT2_NAME")" ## Save windows' positions before autodetection [ ! -d "$SAVEPATH" ] && mkdir -p "$SAVEPATH" -if [ -f "$SAVEPATH"/"$LAST_FILE" ]; then - "$PROG_PATH"/wpos.sh save "$(cat "$SAVEPATH"/"$LAST_FILE")" -fi +"$PROG_PATH"/wpos.sh save "$HASH" ## Main "profiles" logic ## Start with some special command @@ -146,9 +133,6 @@ fi XRANDR="$(xrandr -q)" HASH="$(compute_hash "$XRANDR")" -## Update LAST -echo "$HASH" > "$SAVEPATH"/"$LAST_FILE" - ## Restore known profile if [ -f "$SAVEPATH"/"$HASH" ]; then "$PROG_PATH"/wpos.sh restore "$HASH" |