+#!/bin/bash
+allmonitors="$(xrandr | grep "\( dis\| \)connected" | cut -d' ' -f1)"
+connectedmonitors="$(xrandr | grep " connected" | cut -d' ' -f1)"
+activemonitors="$(xrandr --listmonitors | awk '{print $4}' | grep .)"
+msg=""
+
+# docked
+if lsusb | grep -q '17ef:30b0\|03f0:0620'
+then
+ # two monitors connected, go to only laptop
+ if [ "$(wc -l <<< $connectedmonitors)" -eq 2 ]
+ then
+ msg="${msg}docked"
+ if [[ "$(wc -l <<< "$activemonitors")" -eq 2 ]]
+ then
+ msg="${msg} laptop only"
+ xrandr --output eDP-1 --auto
+ for scr in $allmonitors
+ do
+ if [[ "$scr" != eDP-1 ]]
+ then
+ xrandr --output $scr --off
+ fi
+ done
+ elif [[ "$(wc -l <<< "$activemonitors")" -eq 1 ]]
+ then
+ if [[ "$activemonitors" == eDP-1 ]]
+ then
+ msg="${msg} external only"
+ xrandr --output eDP-1 --off
+ for scr in $connectedmonitors
+ do
+ if [[ "$scr" != eDP-1 ]]
+ then
+ xrandr --output $scr --auto
+ fi
+ done
+ else
+ msg="${msg} both"
+ xrandr --output eDP-1 --auto
+ for scr in $activemonitors
+ do
+ if [[ "$scr" != eDP-1 ]]
+ then
+ xrandr --output $scr --auto --right-of eDP-1
+ fi
+ done
+ fi
+ elif [[ "$(wc -l <<< "$activemonitors")" -eq 0 ]]
+ then
+ msg="${msg} no monitor was active?"
+ xrandr --output eDP-1 --auto
+ fi
+ # one monitor connected, try to swap
+ else
+ msg="${msg}docked and only one monitor connected???" >&2
+ exit 1
+ fi
+else
+ msg="${msg}not docked"
+ # two external monitor is connected
+ if [[ "$(wc -l <<< $connectedmonitors)" -eq 2 ]]
+ then
+ msg="${msg}external monitor is connected"
+ # only one monitor connected (laptop screen)
+ elif [[ "$(wc -l <<< $connectedmonitors)" -eq 1 ]]
+ then
+ msg="${msg}laptop only (no external available)"
+ xrandr --output eDP-1 --auto
+ for scr in $(xrandr | grep "\( dis\| \)connected" | cut -d' ' -f1)
+ do
+ if [ "$scr" == eDP-1 ]
+ then
+ xrandr --output $scr --off
+ fi
+ done
+ elif [[ "$(wc -l <<< $connectedmonitors)" -eq 0 ]]
+ then
+ msg="${msg} no monitor was active?"
+ xrandr --output eDP-1 --auto
+ msg="${msg}external monitor connected"
+ fi
+fi
+notify-send "$msg"
+echo $msg