Skip to content

Commit bd86e0f

Browse files
authored
Merge pull request microsoft#185355 from microsoft/merogge/fish-s
respect `fish_prompt`, re-enable automatic fish shell integration
2 parents f2f7a8e + 203538c commit bd86e0f

File tree

2 files changed

+51
-27
lines changed

2 files changed

+51
-27
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: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,32 @@ 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 __preserve_fish_prompt --on-event fish_prompt
103+
if functions --query fish_prompt
104+
if functions --query __vsc_fish_prompt
105+
# Erase the fallback so it can be set to the user's prompt
106+
functions --erase __vsc_fish_prompt
107+
end
108+
functions --copy fish_prompt __vsc_fish_prompt
109+
functions --erase __preserve_fish_prompt
110+
# Now __vsc_fish_prompt is guaranteed to be defined
111+
__init_vscode_shell_integration
112+
else
113+
if functions --query __vsc_fish_prompt
114+
functions --erase __preserve_fish_prompt
115+
__init_vscode_shell_integration
116+
else
117+
# There is no fish_prompt set, so stick with the default
118+
# Now __vsc_fish_prompt is guaranteed to be defined
119+
function __vsc_fish_prompt
120+
echo -n (whoami)@(prompt_hostname) (prompt_pwd) '~> '
121+
end
122+
end
123+
end
124+
end
125+
__preserve_fish_prompt
126+
101127
# Sent whenever a new fish prompt is about to be displayed.
102128
# Updates the current working directory.
103129
function __vsc_update_cwd --on-event fish_prompt
@@ -128,29 +154,28 @@ function __vsc_fish_has_mode_prompt -d "Returns true if fish_mode_prompt is defi
128154
functions fish_mode_prompt | string match -rvq '^ *(#|function |end$|$)'
129155
end
130156

131-
# Preserve the user's existing prompt, to wrap in our escape sequences.
132-
functions --copy fish_prompt __vsc_fish_prompt
133-
134157
# Preserve and wrap fish_mode_prompt (which appears to the left of the regular
135158
# prompt), but only if it's not defined as an empty function (which is the
136159
# officially documented way to disable that feature).
137-
if __vsc_fish_has_mode_prompt
138-
functions --copy fish_mode_prompt __vsc_fish_mode_prompt
139-
140-
function fish_mode_prompt
141-
__vsc_fish_prompt_start
142-
__vsc_fish_mode_prompt
143-
end
144-
145-
function fish_prompt
146-
__vsc_fish_prompt
147-
__vsc_fish_cmd_start
148-
end
149-
else
150-
# No fish_mode_prompt, so put everything in fish_prompt.
151-
function fish_prompt
152-
__vsc_fish_prompt_start
153-
__vsc_fish_prompt
154-
__vsc_fish_cmd_start
160+
function __init_vscode_shell_integration
161+
if __vsc_fish_has_mode_prompt
162+
functions --copy fish_mode_prompt __vsc_fish_mode_prompt
163+
164+
function fish_mode_prompt
165+
__vsc_fish_prompt_start
166+
__vsc_fish_mode_prompt
167+
end
168+
169+
function fish_prompt
170+
__vsc_fish_prompt
171+
__vsc_fish_cmd_start
172+
end
173+
else
174+
# No fish_mode_prompt, so put everything in fish_prompt.
175+
function fish_prompt
176+
__vsc_fish_prompt_start
177+
__vsc_fish_prompt
178+
__vsc_fish_cmd_start
179+
end
155180
end
156181
end

0 commit comments

Comments
 (0)