#!/bin/bash
echo "Set X credentials in the sudo session to user: "$1
su - $1 -c 'xauth list' |\
grep `echo $DISPLAY |\
cut -d ':' -f 2 |\
cut -d '.' -f 1 |\
sed -e s/^/:/` |\
xargs -n 3 xauth add
Tribute to http://joelinoff.com/blog/?p=729