Skip to content

Commit fc397e0

Browse files
committed
try to get fish prompt to be preserved
1 parent 3170765 commit fc397e0

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

src/vs/platform/terminal/node/terminalEnvironment.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,11 @@ export function getShellIntegrationInjection(
176176
case 'fish': {
177177
// The injection mechanism used for fish is to add a custom dir to $XDG_DATA_DIRS which
178178
// is similar to $ZDOTDIR in zsh but contains a list of directories to run from.
179-
// const oldDataDirs = env?.XDG_DATA_DIRS ?? '/usr/local/share:/usr/share';
180-
// const newDataDir = path.join(appRoot, 'out/vs/workbench/contrib/terminal/browser/media/fish_xdg_data');
181-
// envMixin['XDG_DATA_DIRS'] = `${oldDataDirs}:${newDataDir}`;
182-
// addEnvMixinPathPrefix(options, envMixin);
183-
// return { newArgs: undefined, envMixin };
184-
return undefined;
179+
const oldDataDirs = env?.XDG_DATA_DIRS ?? '/usr/local/share:/usr/share';
180+
const newDataDir = path.join(appRoot, 'out/vs/workbench/contrib/terminal/browser/media/fish_xdg_data');
181+
envMixin['XDG_DATA_DIRS'] = `${oldDataDirs}:${newDataDir}`;
182+
addEnvMixinPathPrefix(options, envMixin);
183+
return { newArgs: undefined, envMixin };
185184
}
186185
case 'pwsh': {
187186
if (!originalArgs || arePwshImpliedArgs(originalArgs)) {

src/vs/workbench/contrib/terminal/browser/media/fish_xdg_data/fish/vendor_conf.d/shellIntegration.fish

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,22 @@ function __vsc_cmd_clear --on-event fish_cancel
9898
__vsc_esc D
9999
end
100100
101+
# Preserve the user's existing prompt, to wrap in our escape sequences.
102+
function init_vscode_shell_integration
103+
echo "$fish_prompt"
104+
functions --copy fish_prompt __vsc_fish_prompt
105+
end
106+
101107
# Sent whenever a new fish prompt is about to be displayed.
102108
# Updates the current working directory.
103109
function __vsc_update_cwd --on-event fish_prompt
110+
if type -q init_vscode_shell_integration
111+
if set -q fish_prompt
112+
init_vscode_shell_integration
113+
functions --erase init_vscode_shell_integration
114+
end
115+
end
116+
104117
__vsc_esc P Cwd=(__vsc_escape_value "$PWD")
105118

106119
# If a command marker exists, remove it.
@@ -128,9 +141,6 @@ function __vsc_fish_has_mode_prompt -d "Returns true if fish_mode_prompt is defi
128141
functions fish_mode_prompt | string match -rvq '^ *(#|function |end$|$)'
129142
end
130143

131-
# Preserve the user's existing prompt, to wrap in our escape sequences.
132-
functions --copy fish_prompt __vsc_fish_prompt
133-
134144
# Preserve and wrap fish_mode_prompt (which appears to the left of the regular
135145
# prompt), but only if it's not defined as an empty function (which is the
136146
# officially documented way to disable that feature).
@@ -143,14 +153,18 @@ if __vsc_fish_has_mode_prompt
143153
end
144154

145155
function fish_prompt
146-
__vsc_fish_prompt
156+
if set -q __vsc_fish_prompt
157+
__vsc_fish_prompt
158+
end
147159
__vsc_fish_cmd_start
148160
end
149161
else
150162
# No fish_mode_prompt, so put everything in fish_prompt.
151163
function fish_prompt
152164
__vsc_fish_prompt_start
153-
__vsc_fish_prompt
165+
if set -q __vsc_fish_prompt
166+
__vsc_fish_prompt
167+
end
154168
__vsc_fish_cmd_start
155169
end
156170
end

0 commit comments

Comments
 (0)