$TERM_PROGRAM is unset when running this from a java ide. This change tests $TERM_PROGRAM before further evaluation.