# just saying this is an array...
#declare -a PRIOR_TERMINAL_TITLES
+#and that whole approach fails; arrays aren't passed to subshells, so any commands
+# that execute in a subshell don't know about the contents and thus don't do what we want.
+#hmmm: revise back to single level memory.
# set the stack position if not already set.
if [ -z "$PTT_STACK_INDEX" ]; then
{
PRIOR_TERMINAL_TITLES[$PTT_STACK_INDEX]="$*"
((PTT_STACK_INDEX++))
-#echo stack index incremented and now at $PTT_STACK_INDEX
-#show_terminal_titles
+echo stack index incremented and now at $PTT_STACK_INDEX
+show_terminal_titles
}
function pop_ptt_stack()
echo nothing to pop from prior terminal titles stack.
else
((PTT_STACK_INDEX--))
-#echo stack index decremented and now at $PTT_STACK_INDEX
+echo stack index decremented and now at $PTT_STACK_INDEX
CURRENT_TERM_TITLE="${PRIOR_TERMINAL_TITLES[$PTT_STACK_INDEX]}"
-#echo "got the last title as '$CURRENT_TERM_TITLE'"
-#show_terminal_titles
+echo "got the last title as '$CURRENT_TERM_TITLE'"
+show_terminal_titles
fi
}
# puts a specific textual label on the terminal title bar.
# this doesn't consider any previous titles; it just labels the terminal.
# the title may not be visible in some window managers.
-function set_terminal_title()
+function reset_terminal_title()
{
title="$*"
# if we weren't given a title, then use just the hostname. this is the degraded functionality.
fi
}
+# user friendly version that saves the title being added.
+function set_terminal_title()
+{
+ save_terminal_title
+ reset_terminal_title $*
+#reading a line made it update.
+#echo "what is title now?"
+#read line
+#this doesn't make it update. echo -n
+echo
+ save_terminal_title
+}
+
# reads the current terminal title, if possible, and saves it to our stack of titles.
function save_terminal_title()
{
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'"
+echo "saving prior terminal title as '$prior_title'"
push_ptt_stack "$prior_title"
-# else
-#echo "not saving prior terminal title which was empty"
+ else
+echo "not saving prior terminal title which was empty"
fi
fi
fi
# run the terminal labeller to restore the prior title, if there was one.
if ! ptt_stack_empty; then
pop_ptt_stack
-#echo "restoring prior terminal title of '$CURRENT_TERM_TITLE'"
- set_terminal_title "$CURRENT_TERM_TITLE"
+echo "restoring prior terminal title of '$CURRENT_TERM_TITLE'"
+ reset_terminal_title "$CURRENT_TERM_TITLE"
fi
}
{
# we only label the terminal anew if there's no saved title.
if ptt_stack_empty; then
+echo "showing new generated title since title stack was empty"
pruned_host=$(echo $HOSTNAME | sed -e 's/^\([^\.]*\)\..*$/\1/')
date_string=$(date +"%Y %b %e @ %T")
user=$USER
user=$USERNAME
fi
new_title="-- $user@$pruned_host -- [$date_string]"
- set_terminal_title "$new_title"
+ reset_terminal_title "$new_title"
else
# use the former title; paste it back up there just in case.
-#echo "showing prior terminal title since there was a prior title!"
+echo "showing prior terminal title since there was a prior title!"
pop_ptt_stack
-#echo "using prior terminal title of '$CURRENT_TERM_TITLE'"
- set_terminal_title "$CURRENT_TERM_TITLE"
+echo "using prior terminal title of '$CURRENT_TERM_TITLE'"
+ reset_terminal_title "$CURRENT_TERM_TITLE"
push_ptt_stack "$CURRENT_TERM_TITLE"
fi
}