reworked saving terminal title
authorChris Koeritz <fred@gruntose.com>
Fri, 13 Jan 2017 20:01:15 +0000 (15:01 -0500)
committerChris Koeritz <fred@gruntose.com>
Fri, 13 Jan 2017 20:01:15 +0000 (15:01 -0500)
customize/fred/scripts/ssh.sh
scripts/core/functions.sh
scripts/tty/label_terminal_with_infos.sh

index 316228c1f01ad16f8ba88b9cfddb3d98aa9db324..2730baa3e148a5f7b39abb815434fd418bdad88c 100644 (file)
@@ -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
index c2f946a8c01ef8a160c0b6af2d737bb8957b0612..b99c1034904492bd36e71e36c15cb3b9a72d042c 100644 (file)
@@ -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
index 91c1312038505592c853f2c5160263923a89d799..291eafd48544a1b5d8442f301caf15119386fbd9 100644 (file)
@@ -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