@theia/terminal 1.70.0-next.71 → 1.70.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/lib/browser/base/terminal-widget.d.ts +40 -1
  2. package/lib/browser/base/terminal-widget.d.ts.map +1 -1
  3. package/lib/browser/base/terminal-widget.js.map +1 -1
  4. package/lib/browser/terminal-command-history.d.ts +27 -0
  5. package/lib/browser/terminal-command-history.d.ts.map +1 -0
  6. package/lib/browser/terminal-command-history.js +76 -0
  7. package/lib/browser/terminal-command-history.js.map +1 -0
  8. package/lib/browser/terminal-frontend-contribution.d.ts +1 -0
  9. package/lib/browser/terminal-frontend-contribution.d.ts.map +1 -1
  10. package/lib/browser/terminal-frontend-contribution.js +20 -0
  11. package/lib/browser/terminal-frontend-contribution.js.map +1 -1
  12. package/lib/browser/terminal-frontend-module.d.ts.map +1 -1
  13. package/lib/browser/terminal-frontend-module.js +3 -0
  14. package/lib/browser/terminal-frontend-module.js.map +1 -1
  15. package/lib/browser/terminal-widget-impl.d.ts +31 -2
  16. package/lib/browser/terminal-widget-impl.d.ts.map +1 -1
  17. package/lib/browser/terminal-widget-impl.js +147 -2
  18. package/lib/browser/terminal-widget-impl.js.map +1 -1
  19. package/lib/common/shell-terminal-protocol.d.ts +6 -0
  20. package/lib/common/shell-terminal-protocol.d.ts.map +1 -1
  21. package/lib/common/shell-terminal-protocol.js.map +1 -1
  22. package/lib/common/terminal-preferences.d.ts +2 -0
  23. package/lib/common/terminal-preferences.d.ts.map +1 -1
  24. package/lib/common/terminal-preferences.js +12 -0
  25. package/lib/common/terminal-preferences.js.map +1 -1
  26. package/lib/node/shell-integration-injector.d.ts +15 -0
  27. package/lib/node/shell-integration-injector.d.ts.map +1 -0
  28. package/lib/node/shell-integration-injector.js +97 -0
  29. package/lib/node/shell-integration-injector.js.map +1 -0
  30. package/lib/node/shell-process.d.ts +6 -0
  31. package/lib/node/shell-process.d.ts.map +1 -1
  32. package/lib/node/shell-process.js.map +1 -1
  33. package/lib/node/terminal-backend-module.d.ts.map +1 -1
  34. package/lib/node/terminal-backend-module.js +7 -1
  35. package/lib/node/terminal-backend-module.js.map +1 -1
  36. package/package.json +10 -10
  37. package/src/browser/base/terminal-widget.ts +52 -1
  38. package/src/browser/style/terminal.css +7 -0
  39. package/src/browser/terminal-command-history.ts +83 -0
  40. package/src/browser/terminal-frontend-contribution.ts +20 -0
  41. package/src/browser/terminal-frontend-module.ts +6 -0
  42. package/src/browser/terminal-widget-impl.ts +171 -4
  43. package/src/common/shell-terminal-protocol.ts +6 -0
  44. package/src/common/terminal-preferences.ts +14 -0
  45. package/src/node/shell-integration-injector.ts +94 -0
  46. package/src/node/shell-integrations/bash/bash-integration.bash +86 -0
  47. package/src/node/shell-integrations/bash/command-block-support.bash +195 -0
  48. package/src/node/shell-integrations/zsh/command-block-support.zsh +103 -0
  49. package/src/node/shell-integrations/zsh/zdotdir/.zlogin +45 -0
  50. package/src/node/shell-integrations/zsh/zdotdir/.zprofile +27 -0
  51. package/src/node/shell-integrations/zsh/zdotdir/.zshenv +56 -0
  52. package/src/node/shell-integrations/zsh/zdotdir/.zshrc +46 -0
  53. package/src/node/shell-integrations/zsh/zdotdir/source-original.zsh +61 -0
  54. package/src/node/shell-integrations/zsh/zsh-integration.zsh +28 -0
  55. package/src/node/shell-process.ts +6 -0
  56. package/src/node/terminal-backend-module.ts +9 -1
@@ -0,0 +1,195 @@
1
+ # *****************************************************************************
2
+ # Copyright (C) 2000-2025 JetBrains s.r.o.
3
+ # Modifications (C) 2025 EclipseSource GmbH and others.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions
14
+ # and limitations under the License.
15
+ #
16
+ # Modifications:
17
+ # - Rebranded functions/vars from `__jetbrains_intellij_*` to `__theia_*`.
18
+ # - Removed the feature gate (`INTELLIJ_TERMINAL_COMMAND_BLOCKS_REWORKED`) so the integration always loads.
19
+ # - Switched OSC protocol from JetBrains `OSC 1341;...` to Theia `OSC 133;...` and changed `command_started` payload
20
+ # to emit only the encoded command (no `command=` key); `command_finished` no longer reports exit code/current directory.
21
+ # - Improved command capture for `command_started`: reads the full command line from `history 1`
22
+ # (strips the history line number with sed) so that pipes, redirects and compound commands are
23
+ # captured as typed; falls back to `BASH_COMMAND` if history is unavailable.
24
+ #
25
+ # Source:
26
+ # https://github.com/JetBrains/intellij-community/blob/8d02751ced444e5b70784fe0a757f960fe495a67/plugins/terminal/resources/shell-integrations/bash/command-block-support-reworked.bash
27
+ # *****************************************************************************
28
+
29
+ __theia_encode_slow() {
30
+ local out=''
31
+ # Use LC_CTYPE=C to process text byte-by-byte and
32
+ # LC_COLLATE=C to compare byte-for-byte. Ensure that
33
+ # LC_ALL and LANG are not set so they don't interfere.
34
+ builtin local i hexch LC_CTYPE=C LC_COLLATE=C LC_ALL= LANG=
35
+ builtin local value="$1"
36
+ for ((i = 1; i <= ${#value}; ++i)); do
37
+ builtin printf -v hexch "%02X" "'$value[i]"
38
+ out+="$hexch"
39
+ done
40
+ builtin printf "%s" "$out"
41
+ }
42
+
43
+ # Util method. Serializes string so that it could be safely passed to the escape sequence payload.
44
+ __theia_encode() {
45
+ builtin local value="$1"
46
+ if builtin command -v od > /dev/null && builtin command -v tr > /dev/null; then
47
+ builtin printf "%s" "$value" | builtin command od -An -tx1 -v | builtin command tr -d "[:space:]"
48
+ else
49
+ __theia_encode_slow "$value"
50
+ fi
51
+ }
52
+
53
+ # Should be executed before command start
54
+ __theia_command_preexec() {
55
+ __theia_command_running="1"
56
+ __theia_should_update_prompt="1"
57
+
58
+ builtin local entered_command
59
+ entered_command="$(history 1 | sed 's/^ *[0-9]\+ *//')" || entered_command="${BASH_COMMAND:-}"
60
+ builtin printf '\e]133;command_started;%s\a' "$(__theia_encode "$entered_command")"
61
+ # Restore the original prompt, our integration will be injected back after command execution in `__theia_update_prompt`.
62
+ PS1="$__theia_original_ps1"
63
+ }
64
+
65
+ # Should be executed before printing of the prompt (for example, after command execution)
66
+ __theia_command_precmd() {
67
+ builtin local LAST_EXIT_CODE="$?"
68
+
69
+ if [[ -z "$__theia_initialized" ]]; then
70
+ __theia_install_debug_trap
71
+ __theia_initialized="1"
72
+ builtin printf '\e]133;initialized\a'
73
+ elif [[ -n "$__theia_command_running" ]]; then
74
+ builtin printf '\e]133;command_finished\a'
75
+ fi
76
+
77
+ if [ -n "$__theia_should_update_prompt" ]; then
78
+ __theia_update_prompt
79
+ fi
80
+
81
+ __theia_should_update_prompt=""
82
+ __theia_command_running=""
83
+ }
84
+
85
+ __theia_update_prompt() {
86
+ if [[ "$__theia_custom_ps1" == "" || "$__theia_custom_ps1" != "$PS1" ]]; then
87
+ # Save the original prompt
88
+ __theia_original_ps1="$PS1"
89
+ __theia_custom_ps1="\[$(__theia_prompt_started)\]$PS1\[$(__theia_prompt_finished)\]"
90
+ PS1="$__theia_custom_ps1"
91
+ fi
92
+ }
93
+
94
+ __theia_prompt_started() {
95
+ builtin printf '\e]133;prompt_started\a'
96
+ }
97
+
98
+ __theia_prompt_finished() {
99
+ builtin printf '\e]133;prompt_finished\a'
100
+ }
101
+
102
+ __theia_install_debug_trap() {
103
+ __theia_original_debug_trap="$(__theia_get_debug_trap)"
104
+ trap '__theia_debug_trap "$_"' DEBUG
105
+ }
106
+
107
+ # Our debug trap is wrapping the original one.
108
+ # We execute our preexec function if conditions are met,
109
+ # but always execute the original trap after that (if any).
110
+ __theia_debug_trap() {
111
+ if __theia_is_prompt_command_contains "${BASH_COMMAND:-}"; then
112
+ # We are executing something inside the PROMPT_COMMAND.
113
+ # It is not the user command, so we need to skip it.
114
+ # But we need to ensure that prompt will be updated.
115
+ # It is important in the case of Ctrl+C in the prompt when there is no running command:
116
+ # in the next precmd we need to update the prompt without sending the command started event.
117
+ __theia_should_update_prompt="1"
118
+ __theia_run_original_debug_trap
119
+ return
120
+ fi
121
+
122
+ # This function is executed in a DEBUG trap, so it can be called multiple times when command is started.
123
+ # But we need to handle only first call.
124
+ if [[ -n "$__theia_command_running" ]]; then
125
+ __theia_run_original_debug_trap
126
+ return
127
+ fi
128
+
129
+ # Execute our preexec function before the original one.
130
+ __theia_command_preexec
131
+
132
+ __theia_run_original_debug_trap
133
+ }
134
+
135
+ __theia_run_original_debug_trap() {
136
+ if [[ -n "$__theia_original_debug_trap" && "$__theia_original_debug_trap" != "-" ]]; then
137
+ builtin eval "${__theia_original_debug_trap}"
138
+ fi
139
+ }
140
+
141
+ # Returns the code that should be executed in the DEBUG trap.
142
+ # 'trap -p DEBUG' outputs a shell command in the format `trap -- '<shell_code>' DEBUG`.
143
+ # The shell code can contain quotes, spaces and line breaks.
144
+ # To get the shell code, we need to parse this string into an array and then get the 2nd item.
145
+ # We have to use `eval` to preserve quoting.
146
+ __theia_get_debug_trap() {
147
+ builtin local -a values
148
+ builtin eval "values=($(trap -p "DEBUG"))"
149
+ builtin printf '%s' "${values[2]:-}"
150
+ }
151
+
152
+ __theia_trim_whitespaces() {
153
+ builtin local text="$1"
154
+ text="${text#"${text%%[![:space:]]*}"}" # Remove leading whitespace characters
155
+ text="${text%"${text##*[![:space:]]}"}" # Remove trailing whitespace characters
156
+ builtin printf '%s' "$text"
157
+ }
158
+
159
+ # Checks if first argument value contains in the PROMPT_COMMAND variable.
160
+ __theia_is_prompt_command_contains() {
161
+ builtin local IFS=$'\n;'
162
+ builtin local prompt_command_array
163
+ builtin read -rd '' -a prompt_command_array <<< "${PROMPT_COMMAND[*]:-}"
164
+
165
+ builtin local text_to_find="$(__theia_trim_whitespaces "$1")"
166
+
167
+ builtin local command
168
+ for command in "${prompt_command_array[@]:-}"; do
169
+ command="$(__theia_trim_whitespaces "$command")"
170
+ if [[ "$command" == "$text_to_find" ]]; then
171
+ return 0
172
+ fi
173
+ done
174
+
175
+ return 1
176
+ }
177
+
178
+ # Inspired by https://unix.stackexchange.com/questions/460651/is-prompt-command-a-colon-separated-list/672843#672843
179
+ __theia_append_to_prompt_command() {
180
+ local separator=$'\n'
181
+ if [[ ${#PROMPT_COMMAND[@]} -gt 1 ]]; then
182
+ PROMPT_COMMAND+=("$1")
183
+ else
184
+ PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND${separator}}${1}"
185
+ fi
186
+ }
187
+
188
+
189
+ __theia_original_ps1=""
190
+ __theia_custom_ps1=""
191
+
192
+ __theia_command_running="1"
193
+ __theia_should_update_prompt="1"
194
+
195
+ __theia_append_to_prompt_command "__theia_command_precmd"
@@ -0,0 +1,103 @@
1
+ # *****************************************************************************
2
+ # Copyright (C) 2000-2025 JetBrains s.r.o.
3
+ # Modifications (C) 2025 EclipseSource GmbH and others.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions
14
+ # and limitations under the License.
15
+ #
16
+ # Modifications:
17
+ # - Renamed functions/vars from `__jetbrains_intellij_*` to `__theia_*`.
18
+ # - Removed gating/early-returns for `INTELLIJ_TERMINAL_COMMAND_BLOCKS_REWORKED` and `P9K_VERSION` (integration always loads).
19
+ # - Switched OSC protocol payloads from JetBrains `OSC 1341;...` to Theia `OSC 133;...` and changed `command_started`
20
+ # format to send only the encoded command (no `command=...` key).
21
+ # - Dropped `command_finished` + `current_directory` reporting and removed alias reporting (`aliases_received`).
22
+ #
23
+ # Source:
24
+ # https://github.com/JetBrains/intellij-community/blob/8d02751ced444e5b70784fe0a757f960fe495a67/plugins/terminal/resources/shell-integrations/zsh/command-block-support-reworked.zsh
25
+ # *****************************************************************************
26
+
27
+ # Disable standard shell integration when Powerlevel10k is detected.
28
+ # P10k's rendering pipeline interferes with external OSC 133 injections.
29
+ # We mirror the behavior of IntelliJ/JetBrains by disabling the external
30
+ # script and deferring to P10k's internal integration.
31
+ #
32
+ # Tracked by JetBrains:
33
+ # https://youtrack.jetbrains.com/issue/IJPL-178955
34
+ [ -n "${P9K_VERSION:-}" ] && builtin return 0
35
+
36
+ __theia_encode_slow() {
37
+ local out=''
38
+ # Use LC_CTYPE=C to process text byte-by-byte and
39
+ # LC_COLLATE=C to compare byte-for-byte. Ensure that
40
+ # LC_ALL and LANG are not set so they don't interfere.
41
+ builtin local i hexch LC_CTYPE=C LC_COLLATE=C LC_ALL= LANG=
42
+ builtin local value="$1"
43
+ for ((i = 1; i <= ${#value}; ++i)); do
44
+ builtin printf -v hexch "%02X" "'$value[i]"
45
+ out+="$hexch"
46
+ done
47
+ builtin print -r "$out"
48
+ }
49
+
50
+ # Encodes the string passed as the first parameter to hex.
51
+ __theia_encode() {
52
+ builtin local value="$1"
53
+ if builtin whence od > /dev/null && builtin whence sed > /dev/null && builtin whence tr > /dev/null; then
54
+ builtin printf "%s" "$value" | builtin command od -v -A n -t x1 | builtin command sed 's/ *//g' | builtin command tr -d '\n'
55
+ else
56
+ __theia_encode_slow "$value"
57
+ fi
58
+ }
59
+
60
+ __theia_command_preexec() {
61
+ builtin local entered_command="$1"
62
+ builtin printf '\e]133;command_started;%s\a' "$(__theia_encode "$entered_command")"
63
+ __theia_command_running="1"
64
+ # Restore the original prompt, our integration will be injected back after command execution in `__theia_update_prompt`.
65
+ PS1="$__theia_original_ps1"
66
+ }
67
+
68
+ __theia_command_precmd() {
69
+ # Should be always the first line in the function!
70
+ builtin local LAST_EXIT_CODE="$?"
71
+
72
+ if [[ -z "${__theia_initialized-}" ]]; then
73
+ # As `precmd` is executed before each prompt, for the first time it is called after
74
+ # all rc files have been processed and before the first prompt is displayed.
75
+ # So, here it finishes the initialization block, not a user command.
76
+ __theia_initialized=1
77
+ builtin printf '\e]133;initialized\a'
78
+ __theia_update_prompt
79
+ builtin return
80
+ fi
81
+ if [ -n "$__theia_command_running" ]; then
82
+ __theia_update_prompt
83
+ __theia_command_running=""
84
+ fi
85
+ }
86
+
87
+ __theia_update_prompt() {
88
+ # Save the original prompt
89
+ __theia_original_ps1="$PS1"
90
+ PS1="%{$(__theia_prompt_started)%}$PS1%{$(__theia_prompt_finished)%}"
91
+ }
92
+
93
+ __theia_prompt_started() {
94
+ builtin printf '\e]133;prompt_started\a'
95
+ }
96
+
97
+ __theia_prompt_finished() {
98
+ builtin printf '\e]133;prompt_finished\a'
99
+ }
100
+
101
+ autoload -Uz add-zsh-hook
102
+ add-zsh-hook preexec __theia_command_preexec
103
+ add-zsh-hook precmd __theia_command_precmd
@@ -0,0 +1,45 @@
1
+ # *****************************************************************************
2
+ # Copyright (C) 2000-2025 JetBrains s.r.o.
3
+ # Modifications (C) 2025 EclipseSource GmbH and others.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions
14
+ # and limitations under the License.
15
+ #
16
+ # Modifications:
17
+ # - Rebranded variables from `JETBRAINS_INTELLIJ_*` to `THEIA_*`.
18
+ # - Removed optional debug logging controlled by `JETBRAINS_INTELLIJ_TERMINAL_DEBUG_LOG_LEVEL`.
19
+ #
20
+ # Source:
21
+ # https://github.com/JetBrains/intellij-community/blob/8d02751ced444e5b70784fe0a757f960fe495a67/plugins/terminal/resources/shell-integrations/zsh/zdotdir/.zlogin
22
+ # *****************************************************************************
23
+
24
+ # See doc in .zshenv for how Theia injects itself into Zsh startup process.
25
+
26
+ # Actually, this file is not expected to be be read, as ZDOTDIR is restored to its
27
+ # original value in the Theia's .zshrc and Theia always starts Zsh in an interactive
28
+ # mode, a behavior that, according to the documentation, cannot be modified afterward:
29
+ #
30
+ # INTERACTIVE shell state option (https://zsh.sourceforge.io/Doc/Release/Options.html)
31
+ # "The value of this option can only be changed via flags supplied at invocation of
32
+ # the shell. It cannot be changed once zsh is running."
33
+ #
34
+ # However, just in case, let's take a safety net and proxy .zlogin.
35
+
36
+ if [[ -n "${THEIA_ORIGINAL_ZDOTDIR-}" ]]; then
37
+ ZDOTDIR="$THEIA_ORIGINAL_ZDOTDIR"
38
+ builtin unset 'THEIA_ORIGINAL_ZDOTDIR'
39
+ else
40
+ # defaults ZDOTDIR to HOME
41
+ builtin unset 'ZDOTDIR'
42
+ fi
43
+
44
+ THEIA_ORIGINAL_FILENAME_TO_SOURCE='.zlogin'
45
+ builtin source "$THEIA_ZSH_DIR/zdotdir/source-original.zsh"
@@ -0,0 +1,27 @@
1
+ # *****************************************************************************
2
+ # Copyright (C) 2000-2025 JetBrains s.r.o.
3
+ # Modifications (C) 2025 EclipseSource GmbH and others.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions
14
+ # and limitations under the License.
15
+ #
16
+ # Modifications:
17
+ # - Rebranded variables from `JETBRAINS_INTELLIJ_*` to `THEIA_*`.
18
+ # - Removed optional debug logging controlled by `JETBRAINS_INTELLIJ_TERMINAL_DEBUG_LOG_LEVEL`.
19
+ #
20
+ # Source:
21
+ # https://github.com/JetBrains/intellij-community/blob/8d02751ced444e5b70784fe0a757f960fe495a67/plugins/terminal/resources/shell-integrations/zsh/zdotdir/.zprofile
22
+ # *****************************************************************************
23
+
24
+ # See doc in .zshenv for how Theia injects itself into Zsh startup process.
25
+
26
+ THEIA_ORIGINAL_FILENAME_TO_SOURCE='.zprofile'
27
+ builtin source "$THEIA_ZSH_DIR/zdotdir/source-original.zsh"
@@ -0,0 +1,56 @@
1
+ # *****************************************************************************
2
+ # Copyright (C) 2000-2025 JetBrains s.r.o.
3
+ # Modifications (C) 2025 EclipseSource GmbH and others.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions
14
+ # and limitations under the License.
15
+ #
16
+ # Modifications:
17
+ # - Rebranded variables from `JETBRAINS_INTELLIJ_*` to `THEIA_*`.
18
+ # - Removed optional debug logging controlled by `JETBRAINS_INTELLIJ_TERMINAL_DEBUG_LOG_LEVEL`.
19
+ #
20
+ # Source:
21
+ # https://github.com/JetBrains/intellij-community/blob/8d02751ced444e5b70784fe0a757f960fe495a67/plugins/terminal/resources/shell-integrations/zsh/zdotdir/.zshenv
22
+ # *****************************************************************************
23
+
24
+ # This is an entry point of Theia Zsh shell integration.
25
+ # The goal is to source `zsh-integration.zsh` file after sourcing the user's ~/.zshrc.
26
+ # This ensures that Theia's `precmd` hook is appended last to the `precmd_functions`
27
+ # array and therefore executed last. This allows control over the PS1 environment
28
+ # variable from the `precmd` hook even if other `precmd` hooks are also modifying it.
29
+
30
+ # According to http://zsh.sourceforge.net/Doc/Release/Files.html, zsh startup configuration files are read in this order:
31
+ # 1. /etc/zshenv
32
+ # 2. $ZDOTDIR/.zshenv
33
+ # 3. /etc/zprofile (if shell is login)
34
+ # 4. $ZDOTDIR/.zprofile (if shell is login)
35
+ # 5. /etc/zshrc (if shell is interactive)
36
+ # 6. $ZDOTDIR/.zshrc (if shell is interactive)
37
+ # 7. /etc/zlogin (if shell is login)
38
+ # 8. $ZDOTDIR/.zlogin (if shell is login)
39
+ #
40
+ # If ZDOTDIR is unset, HOME is used instead.
41
+
42
+ # Theia launches zsh with a custom ZDOTDIR pointing to the parent directory of this file
43
+ # in order to source `zsh-integration.zsh` from the custom .zshrc.
44
+ # However, using a custom ZDOTDIR prevents the user's configuration files
45
+ # (~/.zshenv, ~/.zprofile, ~/.zshrc, ~/.zlogin) from being read.
46
+ # To address this, each user's configuration file is sourced manually from its custom counterpart.
47
+
48
+ # This file is read, because Theia launches zsh with custom ZDOTDIR.
49
+
50
+ # Implementation notes on safe shell scripting:
51
+ # * Use `builtin` prefix to avoid accidentally calling user-defined functions / aliases.
52
+ # * Use ${var-default} or ${var:-default} to not fail in configurations with `setopt nounset`.
53
+ # * Use "${var}" to preserve whitespaces, ${var} will be split into words in configurations with `setopt sh_word_split`.
54
+
55
+ THEIA_ORIGINAL_FILENAME_TO_SOURCE='.zshenv'
56
+ builtin source "$THEIA_ZSH_DIR/zdotdir/source-original.zsh"
@@ -0,0 +1,46 @@
1
+ # *****************************************************************************
2
+ # Copyright (C) 2000-2025 JetBrains s.r.o.
3
+ # Modifications (C) 2025 EclipseSource GmbH and others.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions
14
+ # and limitations under the License.
15
+ #
16
+ # Modifications:
17
+ # - Rebranded variables from `JETBRAINS_INTELLIJ_*` to `THEIA_*`.
18
+ # - Removed optional debug logging controlled by `JETBRAINS_INTELLIJ_TERMINAL_DEBUG_LOG_LEVEL`.
19
+ #
20
+ # Source:
21
+ # https://github.com/JetBrains/intellij-community/blob/8d02751ced444e5b70784fe0a757f960fe495a67/plugins/terminal/resources/shell-integrations/zsh/zdotdir/.zshrc
22
+ # *****************************************************************************
23
+
24
+ # See doc in .zshenv for how Theia injects itself into Zsh startup process.
25
+
26
+ # HISTFILE is set to `${ZDOTDIR:-$HOME}/.zsh_history` in /etc/zshrc when ZDOTDIR
27
+ # pointed to an internal Theia directory, so the HISTFILE variable is set incorrectly.
28
+ # Correct it before sourcing the original .zshrc as user configuration may depend on it.
29
+ HISTFILE="${THEIA_ORIGINAL_ZDOTDIR:-$HOME}/.zsh_history"
30
+
31
+ THEIA_ORIGINAL_FILENAME_TO_SOURCE='.zshrc'
32
+ builtin source "$THEIA_ZSH_DIR/zdotdir/source-original.zsh"
33
+
34
+ # Restore original ZDOTDIR. Once ZDOTDIR is restored, further user configuration files are
35
+ # sourced normally by Zsh. At this point, only .zlogin remains, so it's read directly by Zsh.
36
+ if [[ -n "${THEIA_ORIGINAL_ZDOTDIR-}" ]]; then
37
+ ZDOTDIR="$THEIA_ORIGINAL_ZDOTDIR"
38
+ builtin unset 'THEIA_ORIGINAL_ZDOTDIR'
39
+ else
40
+ # defaults ZDOTDIR to HOME
41
+ builtin unset 'ZDOTDIR'
42
+ fi
43
+
44
+ if [[ -f "${THEIA_ZSH_DIR}/zsh-integration.zsh" ]]; then
45
+ builtin source "${THEIA_ZSH_DIR}/zsh-integration.zsh"
46
+ fi
@@ -0,0 +1,61 @@
1
+ # *****************************************************************************
2
+ # Copyright (C) 2000-2025 JetBrains s.r.o.
3
+ # Modifications (C) 2025 EclipseSource GmbH and others.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions
14
+ # and limitations under the License.
15
+ #
16
+ # Modifications:
17
+ # - Rebranded variables from `JETBRAINS_INTELLIJ_*` to `THEIA_*`.
18
+ # - Removed optional debug logging controlled by `JETBRAINS_INTELLIJ_TERMINAL_DEBUG_LOG_LEVEL`.
19
+ #
20
+ # Source:
21
+ # https://github.com/JetBrains/intellij-community/blob/8d02751ced444e5b70784fe0a757f960fe495a67/plugins/terminal/resources/shell-integrations/zsh/zdotdir/source-original.zsh
22
+ # *****************************************************************************
23
+
24
+ # This is a helper script for loading Zsh user configuration files in the global scope.
25
+ # How to use it:
26
+ # 1. Set THEIA_ORIGINAL_FILENAME_TO_SOURCE to the name of the configuration file to load.
27
+ # 2. Source this script to load the file in the global Zsh scope.
28
+
29
+ # We are in the global scope => prefix variables with `THEIA_`.
30
+
31
+ THEIA_ORIGINAL_FILE="${THEIA_ORIGINAL_ZDOTDIR:-$HOME}/$THEIA_ORIGINAL_FILENAME_TO_SOURCE"
32
+
33
+ if [[ -f "$THEIA_ORIGINAL_FILE" ]]; then
34
+ # prevent recursion, just in case
35
+ if [[ "$ZDOTDIR" != "${THEIA_ORIGINAL_ZDOTDIR:-$HOME}" ]]; then
36
+ THEIA_ZDOTDIR_COPY="$ZDOTDIR"
37
+
38
+ # Correct ZDOTDIR before sourcing the user's file as it might rely on the value of ZDOTDIR.
39
+ if [[ -n "$THEIA_ORIGINAL_ZDOTDIR" ]]; then
40
+ ZDOTDIR="$THEIA_ORIGINAL_ZDOTDIR"
41
+ else
42
+ builtin unset ZDOTDIR # defaults ZDOTDIR to HOME
43
+ fi
44
+
45
+ builtin source "$THEIA_ORIGINAL_FILE"
46
+
47
+ # ZDOTDIR might be changed by the user config
48
+ if [[ -n "$ZDOTDIR" ]]; then
49
+ THEIA_ORIGINAL_ZDOTDIR="$ZDOTDIR"
50
+ else
51
+ builtin unset THEIA_ORIGINAL_ZDOTDIR
52
+ fi
53
+
54
+ # Set back to the Theia location to continue injecting Theia shell integration.
55
+ ZDOTDIR="$THEIA_ZDOTDIR_COPY"
56
+ fi
57
+ fi
58
+
59
+ builtin unset THEIA_ORIGINAL_FILE
60
+ builtin unset THEIA_ZDOTDIR_COPY
61
+ builtin unset THEIA_ORIGINAL_FILENAME_TO_SOURCE
@@ -0,0 +1,28 @@
1
+ # *****************************************************************************
2
+ # Copyright (C) 2000-2025 JetBrains s.r.o.
3
+ # Modifications (C) 2025 EclipseSource GmbH and others.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions
14
+ # and limitations under the License.
15
+ #
16
+ # Modifications:
17
+ # - Adapted directory variable: `JETBRAINS_INTELLIJ_ZSH_DIR` -> `THEIA_ZSH_DIR`.
18
+ # - Removed IntelliJ session bootstrap (JEDITERM_SOURCE and `_INTELLIJ_FORCE_SET_*` / `_INTELLIJ_FORCE_PREPEND_*` handling,
19
+ # plus the one-time `precmd_functions` hook injection).
20
+ # - Removed legacy command block support handling.
21
+ #
22
+ # Source:
23
+ # https://github.com/JetBrains/intellij-community/blob/8d02751ced444e5b70784fe0a757f960fe495a67/plugins/terminal/resources/shell-integrations/zsh/zsh-integration.zsh
24
+ # *****************************************************************************
25
+
26
+ builtin local command_block_support="${THEIA_ZSH_DIR}/command-block-support.zsh"
27
+ [ -r "$command_block_support" ] && builtin source "$command_block_support"
28
+ builtin unset THEIA_ZSH_DIR
@@ -37,6 +37,12 @@ export interface ShellProcessOptions {
37
37
  env?: { [key: string]: string | null },
38
38
  strictEnv?: boolean,
39
39
  isPseudo?: boolean,
40
+ /**
41
+ * Whether to inject shell integration scripts for command tracking.
42
+ * When enabled, shell integration scripts are injected to emit OSC 133 sequences.
43
+ * @default false
44
+ */
45
+ enableShellIntegration?: boolean;
40
46
  }
41
47
 
42
48
  export function getRootPath(rootURI?: string): string {
@@ -26,6 +26,7 @@ import { ShellTerminalServer } from '../node/shell-terminal-server';
26
26
  import { TerminalWatcher } from '../common/terminal-watcher';
27
27
  import { MessagingService } from '@theia/core/lib/node/messaging/messaging-service';
28
28
  import { bindTerminalPreferences } from '../common/terminal-preferences';
29
+ import { ShellIntegrationInjector } from './shell-integration-injector';
29
30
 
30
31
  export function bindTerminalServer(bind: interfaces.Bind, { path, identifier, constructor }: {
31
32
  path: string,
@@ -57,11 +58,18 @@ export default new ContainerModule(bind => {
57
58
  bind(MessagingService.Contribution).to(TerminalBackendContribution).inSingletonScope();
58
59
 
59
60
  bind(ShellProcess).toSelf().inTransientScope();
61
+ bind(ShellIntegrationInjector).toSelf().inSingletonScope();
60
62
  bind(ShellProcessFactory).toFactory(ctx =>
61
63
  (options: ShellProcessOptions) => {
62
64
  const child = new Container({ defaultScope: 'Singleton' });
63
65
  child.parent = ctx.container;
64
- child.bind(ShellProcessOptions).toConstantValue(options);
66
+
67
+ // inject shell integration scripts and env vars only if the terminal command history is enabled
68
+ const injectedOptions = (options.enableShellIntegration ?? false)
69
+ ? ctx.container.get(ShellIntegrationInjector).injectShellIntegration(options)
70
+ : options;
71
+
72
+ child.bind(ShellProcessOptions).toConstantValue(injectedOptions);
65
73
  return child.get(ShellProcess);
66
74
  }
67
75
  );