Fix DISPLAY variable loss with newgrp
At one of my clients, they use newgrp a lot, to switch between configuration for ClearCase views and such. When using newgrp, $DISPLAY tends to go away, which is pretty darn annoying.
During previous engagements at this client, I just hardcoded a value, which worked for Exceed. However, now I'm using xming via ssh, and it changes the display value each time it's started. I needed another workaround.
My final solution has two parts:
1. A new alias:
alias newgrp='echo $DISPLAY > ~/.newgrp.DISPLAY && newgrp'
2. A bit of code in ~/.profile:g
###########################################
# Set the display, if it's not already set
###########################################
# Sometimes, this gets lost between newgrps, etc.
if [ ! "${DISPLAY}" ]
then
if [[ -r ${HOME}/.newgrp.DISPLAY ]]
then
typeset -x DISPLAY=$(cat ${HOME}/.newgrp.DISPLAY)
rm ${HOME}/.newgrp.DISPLAY
fi
fi