From a255159a45fdfaa6a20e958bd2b123982086990f Mon Sep 17 00:00:00 2001 From: Chris Koeritz Date: Thu, 9 Mar 2017 10:44:16 -0500 Subject: [PATCH] terminal stuff is hosed need to revert to older version that simply used a single level memory of the title. --- scripts/tty/terminal_titler.sh | 47 +++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/scripts/tty/terminal_titler.sh b/scripts/tty/terminal_titler.sh index eddfb510..c93879d4 100644 --- a/scripts/tty/terminal_titler.sh +++ b/scripts/tty/terminal_titler.sh @@ -5,6 +5,9 @@ source "$FEISTY_MEOW_SCRIPTS/core/common.alias" # 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 @@ -46,8 +49,8 @@ function push_ptt_stack() { 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() @@ -56,17 +59,17 @@ 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. @@ -84,6 +87,19 @@ function set_terminal_title() 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() { @@ -94,10 +110,10 @@ 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 @@ -113,8 +129,8 @@ function restore_terminal_title() # 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 } @@ -123,6 +139,7 @@ function label_terminal_with_info() { # 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 @@ -131,13 +148,13 @@ function label_terminal_with_info() 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 } -- 2.34.1