Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: OSC133 outputs shouldn't be printed in non-interactive mode



Oliver Kiddle <opk@xxxxxxx> writes:

> Daniel Colascione wrote:
>> > I'd be inclined to add the isset(INTERACTIVE) condition earlier in
>> > the call stack such as around the zleentry() calls in init.c for
>> > ZLE_CMD_PREEXEC and ZLE_CMD_POSTEXEC instead. Anyone have an opinion
>> > on that?
>>
>> Let me know if you want me to refresh the patch.
>
> If you don't mind then a refresh would be useful. Perhaps post to
> zsh-workers rather than -users. Though -users is fine too if you prefer.

How's this?

commit 966854b80ced77ac3b80ee57ce6519ecfadbae97
Author: Daniel Colascione <dancol@xxxxxxxxxx>
Date:   Sun Jul 12 15:52:40 2026 -0400

    Avoid OSC 133 markers in noninteractive shells

diff --git a/Src/init.c b/Src/init.c
index f36bc332b..10802669c 100644
--- a/Src/init.c
+++ b/Src/init.c
@@ -224,7 +224,7 @@ loop(int toplevel, int justonce)
 		 */
 		errflag &= ~ERRFLAG_ERROR;
 	    }
-	    if (toplevel && zle_load_state == 1)
+	    if (interact && toplevel && zle_load_state == 1)
 		zleentry(ZLE_CMD_PREEXEC);
 	    if (stopmsg)	/* unset 'you have stopped jobs' flag */
 		stopmsg--;
@@ -232,7 +232,7 @@ loop(int toplevel, int justonce)
 	    tok = toksav;
 	    if (toplevel) {
 		noexitct = 0;
-		if (zle_load_state == 1)
+		if (interact && zle_load_state == 1)
 		    zleentry(ZLE_CMD_POSTEXEC);
 	    }
 	}
diff --git a/Test/X06termquery.ztst b/Test/X06termquery.ztst
index 701cd625b..04d9c4626 100644
--- a/Test/X06termquery.ztst
+++ b/Test/X06termquery.ztst
@@ -19,6 +19,39 @@
       { zpty -r zsh } | tr -d '\015' | grep -v '^ '
       zpty -d
     }
+    noninteractive_integration() {
+      setopt localoptions extendedglob
+      local REPLY chunk out=
+      zpty -d
+      zpty zsh "${(q)ZTST_testdir}/../Src/zsh +i -f"
+      zpty -w zsh "module_path=( ${(j< >)${(@q-)module_path}} \$module_path )"
+      zpty -w zsh 'zmodload zsh/zle'
+      sleep 0.1
+      while zpty -r -t zsh chunk \*; do
+        out+=$chunk
+      done
+      zpty -w zsh 'print -r -- PAYLOAD'
+      sleep 0.1
+      while zpty -r -t zsh chunk \*; do
+        out+=$chunk
+      done
+      zpty -w zsh exit
+      sleep 0.1
+      while zpty -r -t zsh chunk \*; do
+        out+=$chunk
+      done
+      zpty -d
+      if [[ $out == *$'\e]133;'* ]]; then
+        print 'noninteractive: OSC 133 emitted'
+      else
+        print 'noninteractive: no OSC 133'
+      fi
+      if [[ $out == *PAYLOAD* ]]; then
+        print 'noninteractive: payload'
+      else
+        print 'noninteractive: missing payload'
+      fi
+    }
   else
     ZTST_unimplemented='the zsh/zpty module is not available'
   fi
@@ -106,6 +139,11 @@
 >replace
 >typeset -a .term.extensions=( -bracketed-paste -integration )
 
+  noninteractive_integration
+0:Noninteractive shells do not emit OSC 133 markers after loading ZLE
+>noninteractive: no OSC 133
+>noninteractive: payload
+
 %clean
 
   zmodload -ui zsh/zpty






Messages sorted by: Reverse Date, Date, Thread, Author