-# save the former terminal title if we're running in X with xterm.
-prior_title=
-which xprop &>/dev/null
-if [ $? -eq 0 ]; then
- if [[ "$TERM" =~ .*"xterm".* ]]; then
- prior_title="$(xprop -id $WINDOWID | perl -nle 'print $1 if /^WM_NAME.+= \"(.*)\"$/')"
+if [ -z "$PRIOR_TERMINAL_TITLE" ]; then
+ # save the former terminal title if we're running in X with xterm.
+ PRIOR_TERMINAL_TITLE=
+ which xprop &>/dev/null
+ if [ $? -eq 0 ]; then
+ if [[ "$TERM" =~ .*"xterm".* ]]; then
+ PRIOR_TERMINAL_TITLE="$(xprop -id $WINDOWID | perl -nle 'print $1 if /^WM_NAME.+= \"(.*)\"$/')"
+ fi