[vte/vte-0-66] vte.sh: Use PROMPT_COMMAND as an array when possible



commit 5791f72343582a131acdfce1334415dbc12ad3f7
Author: Christian Persch <chpe src gnome org>
Date:   Sat Aug 28 22:00:06 2021 +0200

    vte.sh: Use PROMPT_COMMAND as an array when possible
    
    Newer bash versions support PROMPT_COMMAND as an array. In this case,
    add only the __vte_osc7 command to the array, instead of overwriting
    the PROMPT_COMMAND with __vte_prompt_command.
    
    Fixes: https://gitlab.gnome.org/GNOME/vte/-/issues/37
    (cherry picked from commit e67d15735e1410e139f8e1943cc6ca728524c34d)

 src/vte.sh.in | 31 ++++++++++++++++++++++++-------
 1 file changed, 24 insertions(+), 7 deletions(-)
---
diff --git a/src/vte.sh.in b/src/vte.sh.in
index 3ac99d7e..1aa40ba4 100644
--- a/src/vte.sh.in
+++ b/src/vte.sh.in
@@ -22,6 +22,12 @@
 # Not running under vte?
 [ "${VTE_VERSION:-0}" -ge 3405 ] || return 0
 
+# TERM not supported?
+case "$TERM" in
+    xterm*|vte*|gnome*) :;;
+    *) return 0 ;;
+esac
+
 __vte_osc7 () {
   printf "\033]7;file://%s%s\033\\" "${HOSTNAME}" "$(@libexecdir@/vte-urlencode-cwd)"
 }
@@ -34,11 +40,22 @@ __vte_prompt_command() {
   __vte_osc7
 }
 
-case "$TERM" in
-  xterm*|vte*)
-    [ -n "${BASH_VERSION:-}" ] && PROMPT_COMMAND="__vte_prompt_command"
-    [ -n "${ZSH_VERSION:-}"  ] && precmd_functions+=(__vte_osc7)
-    ;;
-esac
+if [[ -n "${BASH_VERSION:-}" ]]; then
+
+    # Newer bash versions support PROMPT_COMMAND as an array. In this case
+    # only add the __vte_osc7 function to it, and leave setting the terminal
+    # title to the outside setup.
+    # On older bash, we can only overwrite the whole PROMPT_COMMAND, so must
+    # use the __vte_prompt_command function which also sets the title.
+
+    if [[ "$(declare -p PROMPT_COMMAND)" =~ "declare -a" ]]; then
+       PROMPT_COMMAND+=(__vte_osc7)
+    else
+       PROMPT_COMMAND="__vte_prompt_command"
+    fi
+
+elif [[ -n "${ZSH_VERSION:-}" ]]; then
+    precmd_functions+=(__vte_osc7)
+fi
 
-true
+return 0


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]