diff --git a/extensions/InjectShellIntegration/src/ScriptBuilders.ts b/extensions/InjectShellIntegration/src/ScriptBuilders.ts index 5377c0bd0..f7ce59425 100644 --- a/extensions/InjectShellIntegration/src/ScriptBuilders.ts +++ b/extensions/InjectShellIntegration/src/ScriptBuilders.ts @@ -175,14 +175,22 @@ export class ZshScriptBuilder extends ScriptBuilder { protected _buildShellReporting(): string { return ` -if [[ ! "$PS1" =~ "${this._extratermCookieValue}" ]] ; then - export PS1=\`echo -n -e "%{\\033&${this._extratermCookieValue};3\\007%}%?%{\\000%}\${PS1}"\` -fi +autoload -Uz add-zsh-hook +extraterm_install_prompt_integration () { + local prefix + if [[ ! "$PS1" =~ "${this._extratermCookieValue}" ]] ; then + prefix=\`echo -n -e "%{\\0033&${this._extratermCookieValue};3\\0007%}%?%{\\0000%}"\` + export PS1="\${prefix}\${PS1}" + fi +} +extraterm_install_prompt_integration +add-zsh-hook precmd extraterm_install_prompt_integration + preexec () { - echo -n -e "\\033&\${${this._extratermCookieName}};2;zsh\\007" + echo -n -e "\\0033&\${${this._extratermCookieName}};2;zsh\\0007" echo -n $1 - echo -n -e "\\000" + echo -n -e "\\0000" } `; } diff --git a/src/commands/setup_extraterm_zsh.zsh b/src/commands/setup_extraterm_zsh.zsh index 6f2f66692..e3bc51022 100644 --- a/src/commands/setup_extraterm_zsh.zsh +++ b/src/commands/setup_extraterm_zsh.zsh @@ -6,6 +6,8 @@ # if [ -n "$LC_EXTRATERM_COOKIE" ]; then + autoload -Uz add-zsh-hook + echo "Setting up Extraterm support." # Put our enhanced commands at the start of the PATH. @@ -13,12 +15,21 @@ if [ -n "$LC_EXTRATERM_COOKIE" ]; then export PATH="$PWD/$filedir:$PATH" # Insert our special code to communicate to Extraterm the status of the last command. - export PS1=`echo -n -e "%{\033&${LC_EXTRATERM_COOKIE};3\007%}%?%{\000%}${PS1}"` - + extraterm_install_prompt_integration () { + local prefix + + if [[ ! "$PS1" =~ "$LC_EXTRATERM_COOKIE" ]] ; then + prefix=`echo -n -e "%{\0033&${LC_EXTRATERM_COOKIE};3\0007%}%?%{\0000%}"` + export PS1="${prefix}${PS1}" + fi + } + extraterm_install_prompt_integration + add-zsh-hook precmd extraterm_install_prompt_integration + preexec () { - echo -n -e "\033&${LC_EXTRATERM_COOKIE};2;zsh\007" + echo -n -e "\0033&${LC_EXTRATERM_COOKIE};2;zsh\0007" echo -n $1 - echo -n -e "\000" + echo -n -e "\0000" } # Look for Python 3 support.