- # save the former terminal title if we're running in X with xterm.
- which xprop &>/dev/null
- if [ $? -eq 0 ]; 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'"
- push_ptt_stack "$prior_title"
-# else
-#echo "not saving prior terminal title which was empty"
- fi
+ local title="$*"
+
+ if [ -z "$title" ]; then
+ if [ ! -z "$DEBUG_TERM_TITLE" ]; then
+ echo "terminal_titler: empty title: pushing current title again"
+ fi
+ peek_title_stack
+ title="$LAST_TITLE"
+ if [ -z "$title" ]; then
+ log_feisty_meow_event "terminal_titler: there was no saved title, so we're ignoring the save attempt."
+ return 1
+ fi
+ fi
+
+#hmmm: need a validation step here to remove bad chars that conflict with our title compression scheme.
+
+ # only slap a comma after the existing value if it wasn't empty.
+ if [ -z "$TERMINAL_TITLE_STACK" ]; then
+ export TERMINAL_TITLE_STACK="\"$title\""
+ else
+ export TERMINAL_TITLE_STACK="$TERMINAL_TITLE_STACK,\"$title\""
+ fi
+
+ if [ ! -z "$DEBUG_TERM_TITLE" ]; then
+ echo "terminal_titler: new terminal title stack is:"
+ echo "$TERMINAL_TITLE_STACK"
+ fi
+}
+
+# takes a terminal title off the stack and sets the LAST_TITLE variable.
+function pop_title_stack()
+{
+ # whack our output variable, just in case.
+ unset LAST_TITLE
+ # get our stack top.
+ peek_title_stack
+ # trim the popped item out of the stack.
+ if [ ! -z "$TERMINAL_TITLE_STACK" ]; then
+ TERMINAL_TITLE_STACK="$(echo $TERMINAL_TITLE_STACK | sed -n -e 's/\(.*\),[^,]*$/\1/p')"
+ fi
+}
+
+# like pop, but does not change the stack, effectively handing you the most
+# recently set title.
+function peek_title_stack()
+{
+ # whack our output variable, just in case.
+ unset LAST_TITLE
+
+ if [ ! -z "$TERMINAL_TITLE_STACK" ]; then
+ LAST_TITLE="$(echo $TERMINAL_TITLE_STACK | sed -n -e 's/.*","\([^,]*\)"$/\1/p')"
+ if [ -z "$LAST_TITLE" ]; then
+ LAST_TITLE="$(echo $TERMINAL_TITLE_STACK | sed -n -e 's/"//gp')"