-if [ -n "$DISPLAY" ]; then
- export XAUTHORITY="$XDG_RUNTIME_DIR/Xauthority"
- read protocol cookie
- xauth remove $DISPLAY
- xauth add $DISPLAY "$protocol" "$cookie"
+if read proto cookie && [ -n "$DISPLAY" ]; then
+ if [ `echo $DISPLAY | cut -c1-10` = "localhost:" ]; then
+ echo add unix:`echo $DISPLAY | cut -c11-` $proto $cookie
+ else
+ echo add $DISPLAY "$protocol" "$cookie"
+ fi | xauth -q -