do not emit term codes if not term
[feisty_meow.git] / scripts / tty / terminal_titler.sh
index 3751ba24f781dfab48fa63dd481fc89722645ed2..f4a18282bac6fd7e2212c4726044e60f2bb4ba82 100644 (file)
@@ -1,6 +1,6 @@
 #!/bin/bash
 
-source $FEISTY_MEOW_SCRIPTS/core/functions.sh
+source "$FEISTY_MEOW_SCRIPTS/core/functions.sh"
 
 # just saying this is an array...
 #declare -a PRIOR_TERMINAL_TITLES
@@ -72,7 +72,15 @@ function set_terminal_title()
   if [ -z "${title}" ]; then
     title="$(hostname)"
   fi
-  echo -n -e "\033]0;${title}\007"
+  
+  if [ -z "$PS1" ]; then
+    # not running interactively, so just echo the title.
+    sep
+    echo ${title}
+    sep
+  else
+    echo -n -e "\033]0;${title}\007"
+  fi
 }
 
 # reads the current terminal title, if possible, and saves it to our stack of titles.
@@ -81,7 +89,8 @@ function save_terminal_title()
   # save the former terminal title if we're running in X with xterm.
   which xprop &>/dev/null
   if [ $? -eq 0 ]; then
-    if [[ "$TERM" =~ .*"xterm".* ]]; then
+    # make sure we're actually using xterm *and* that we have a window ID.
+    if [[ "$TERM" =~ .*"xterm".* && ! -z "$WINDOWID" ]]; then
       local prior_title="$(xprop -id $WINDOWID | perl -nle 'print $1 if /^WM_NAME.+= \"(.*)\"$/')"
       if [ ! -z "$prior_title" ]; then
 #echo "saving prior terminal title as '$prior_title'"