From 1a64085683a99b940156fdf19ed277ca08bf6545 Mon Sep 17 00:00:00 2001 From: Chris Koeritz Date: Fri, 13 Jan 2017 15:01:15 -0500 Subject: [PATCH] reworked saving terminal title --- customize/fred/scripts/ssh.sh | 24 +++++++++++++--------- scripts/core/functions.sh | 6 ++++-- scripts/tty/label_terminal_with_infos.sh | 26 ++++++++++++++++-------- 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/customize/fred/scripts/ssh.sh b/customize/fred/scripts/ssh.sh index 316228c1..2730baa3 100644 --- a/customize/fred/scripts/ssh.sh +++ b/customize/fred/scripts/ssh.sh @@ -4,12 +4,14 @@ source "$FEISTY_MEOW_LOADING_DOCK/custom/scripts/pick_credentials.sh" -# 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 fi fi @@ -36,12 +38,14 @@ if [ $? -eq 0 ]; then if [ -z "$(echo $* | grep git)" ]; then # re-run the terminal labeller after coming back from ssh. # we check the exit value because we don't want to update this for a failed connection. - if [ -z "$prior_title" ]; then -#echo prior title nil new label + if [ -z "$PRIOR_TERMINAL_TITLE" ]; then +echo prior title nil new label bash $FEISTY_MEOW_SCRIPTS/tty/label_terminal_with_infos.sh else -#echo "using old prior title of '$prior_title'" - bash $FEISTY_MEOW_SCRIPTS/tty/set_term_title.sh "$prior_title" +echo "using old prior title of '$PRIOR_TERMINAL_TITLE'" + bash $FEISTY_MEOW_SCRIPTS/tty/set_term_title.sh "$PRIOR_TERMINAL_TITLE" + # remove the value for this, since we did our job on it. + unset PRIOR_TERMINAL_TITLE fi fi fi diff --git a/scripts/core/functions.sh b/scripts/core/functions.sh index c2f946a8..b99c1034 100644 --- a/scripts/core/functions.sh +++ b/scripts/core/functions.sh @@ -316,8 +316,10 @@ if [ -z "$skip_all" ]; then /bin/su -l $* fi - # relabel the console after returning. - bash $FEISTY_MEOW_SCRIPTS/tty/label_terminal_with_infos.sh +#NO! # relabel the console after returning. +#NO! bash $FEISTY_MEOW_SCRIPTS/tty/label_terminal_with_infos.sh +# fix this to set the old title back in place! + } # sudo function wraps the normal sudo by ensuring we replace the terminal diff --git a/scripts/tty/label_terminal_with_infos.sh b/scripts/tty/label_terminal_with_infos.sh index 91c13120..291eafd4 100644 --- a/scripts/tty/label_terminal_with_infos.sh +++ b/scripts/tty/label_terminal_with_infos.sh @@ -5,15 +5,23 @@ source $FEISTY_MEOW_SCRIPTS/core/functions.sh -pruned_host=$(echo $HOSTNAME | sed -e 's/^\([^\.]*\)\..*$/\1/') -date_string=$(date +"%Y %b %e @ %T") +# we only label the terminal anew if there's no saved title. + +#hmmm: how about putting that title back in place? +# we currently do this manually in places, like ssh, which is dumb. -user=$USER -if [ -z "$user" ]; then - # try snagging the windoze name. - user=$USERNAME -fi -new_title="-- $user@$pruned_host -- [$date_string]" +if [ -z "$PRIOR_TERMINAL_TITLE" ]; then + pruned_host=$(echo $HOSTNAME | sed -e 's/^\([^\.]*\)\..*$/\1/') + date_string=$(date +"%Y %b %e @ %T") -bash "$FEISTY_MEOW_SCRIPTS/tty/set_term_title.sh" "$new_title" + user=$USER + if [ -z "$user" ]; then + # try snagging the windoze name. + user=$USERNAME + fi + + new_title="-- $user@$pruned_host -- [$date_string]" + + bash "$FEISTY_MEOW_SCRIPTS/tty/set_term_title.sh" "$new_title" +fi -- 2.34.1