Skip to content

Commit a7f9339

Browse files
authored
Merge pull request microsoft#157291 from zgracem/fish-shell-integration
add shell integration script for fish
2 parents 1141808 + 36e2df6 commit a7f9339

File tree

7 files changed

+94
-1
lines changed

7 files changed

+94
-1
lines changed

build/filters.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ module.exports.copyrightFilter = [
139139
'!**/*.xml',
140140
'!**/*.sh',
141141
'!**/*.zsh',
142+
'!**/*.fish',
142143
'!**/*.txt',
143144
'!**/*.xpm',
144145
'!**/*.opts',

build/gulpfile.reh.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,14 @@ const serverResources = [
7676
'out-build/vs/base/node/ps.sh',
7777

7878
// Terminal shell integration
79+
'out-build/vs/workbench/contrib/terminal/browser/media/shellIntegration.fish',
7980
'out-build/vs/workbench/contrib/terminal/browser/media/shellIntegration.ps1',
8081
'out-build/vs/workbench/contrib/terminal/browser/media/shellIntegration-bash.sh',
8182
'out-build/vs/workbench/contrib/terminal/browser/media/shellIntegration-env.zsh',
8283
'out-build/vs/workbench/contrib/terminal/browser/media/shellIntegration-profile.zsh',
8384
'out-build/vs/workbench/contrib/terminal/browser/media/shellIntegration-rc.zsh',
8485
'out-build/vs/workbench/contrib/terminal/browser/media/shellIntegration-login.zsh',
86+
'out-build/vs/workbench/contrib/terminal/browser/media/shellIntegration.fish',
8587

8688
'!**/test/**'
8789
];

build/gulpfile.vscode.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ const vscodeResources = [
6868
'out-build/vs/workbench/browser/media/*-theme.css',
6969
'out-build/vs/workbench/contrib/debug/**/*.json',
7070
'out-build/vs/workbench/contrib/externalTerminal/**/*.scpt',
71+
'out-build/vs/workbench/contrib/terminal/browser/media/*.fish',
7172
'out-build/vs/workbench/contrib/terminal/browser/media/*.ps1',
7273
'out-build/vs/workbench/contrib/terminal/browser/media/*.sh',
7374
'out-build/vs/workbench/contrib/terminal/browser/media/*.zsh',

src/vs/code/node/cli.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ export async function main(argv: string[]): Promise<any> {
7171
case 'pwsh': file = 'shellIntegration.ps1'; break;
7272
// Usage: `[[ "$TERM_PROGRAM" == "vscode" ]] && . "$(code --locate-shell-integration-path zsh)"`
7373
case 'zsh': file = 'shellIntegration-rc.zsh'; break;
74+
// Usage: `string match -q "$TERM_PROGRAM" "vscode"; and . (code --locate-shell-integration-path fish)`
75+
case 'fish': file = 'shellIntegration.fish'; break;
7476
default: throw new Error('Error using --locate-shell-integration-path: Invalid shell type');
7577
}
7678
console.log(join(dirname(FileAccess.asFileUri('', require)).fsPath, 'out', 'vs', 'workbench', 'contrib', 'terminal', 'browser', 'media', file));

src/vs/platform/environment/node/argv.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export const OPTIONS: OptionDescriptions<Required<NativeParsedArgs>> = {
128128
'logsPath': { type: 'string' },
129129
'__enable-file-policy': { type: 'boolean' },
130130
'editSessionId': { type: 'string' },
131-
'locate-shell-integration-path': { type: 'string', args: ['bash', 'pwsh', 'zsh'] },
131+
'locate-shell-integration-path': { type: 'string', args: ['bash', 'pwsh', 'zsh', 'fish'] },
132132

133133
// chromium flags
134134
'no-proxy-server': { type: 'boolean' },

src/vs/server/node/server.cli.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ export async function main(desc: ProductDescription, args: string[]): Promise<vo
144144
case 'pwsh': file = 'shellIntegration.ps1'; break;
145145
// Usage: `[[ "$TERM_PROGRAM" == "vscode" ]] && . "$(code --locate-shell-integration-path zsh)"`
146146
case 'zsh': file = 'shellIntegration-rc.zsh'; break;
147+
// Usage: `string match -q "$TERM_PROGRAM" "vscode"; and . (code --locate-shell-integration-path fish)`
148+
case 'fish': file = 'shellIntegration-fish.fish'; break;
147149
default: throw new Error('Error using --locate-shell-integration-path: Invalid shell type');
148150
}
149151
console.log(resolve(__dirname, '../..', 'workbench', 'contrib', 'terminal', 'browser', 'media', file));
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# ---------------------------------------------------------------------------------------------
2+
# Copyright (c) Microsoft Corporation. All rights reserved.
3+
# Licensed under the MIT License. See License.txt in the project root for license information.
4+
# ---------------------------------------------------------------------------------------------
5+
#
6+
# Visual Studio Code terminal integration for fish
7+
#
8+
# Manual installation:
9+
#
10+
# (1) Add the following to the end of `$__fish_config_dir/config.fish`:
11+
#
12+
# string match -q "$TERM_PROGRAM" "vscode"
13+
# and . (code --locate-shell-integration-path fish)
14+
#
15+
# (2) Restart fish.
16+
17+
# Don't run in scripts, other terminals, or more than once per session.
18+
status is-interactive
19+
and string match --quiet "$TERM_PROGRAM" "vscode"
20+
and ! set --query VSCODE_SHELL_INTEGRATION
21+
or exit
22+
23+
set --global VSCODE_SHELL_INTEGRATION 1
24+
25+
# Helper function
26+
function __vsc_esc -d "Emit escape sequences for VS Code shell integration"
27+
builtin printf "\e]633;%s\007" (string join ";" $argv)
28+
end
29+
30+
# Sent right before executing an interactive command.
31+
# Marks the beginning of command output.
32+
function __vsc_cmd_executed --on-event fish_preexec
33+
__vsc_esc C
34+
__vsc_esc E (__vsc_escape_cmd "$argv")
35+
end
36+
37+
38+
# Escapes backslashes, newlines, and semicolons to serialize the command line.
39+
function __vsc_escape_cmd
40+
set -l commandline "$argv"
41+
# `string replace` automatically breaks its input apart on any newlines.
42+
# Then `string join` at the end will bring it all back together.
43+
string replace --all '\\' '\\\\' $commandline \
44+
| string replace --all ';' '\x3b' \
45+
| string join '\x0a'
46+
end
47+
48+
# Sent right after an interactive command has finished executing.
49+
# Marks the end of command output.
50+
function __vsc_cmd_finished --on-event fish_postexec
51+
__vsc_esc D $status
52+
end
53+
54+
# Sent when a command line is cleared or reset, but no command was run.
55+
# Marks the cleared line with neither success nor failure.
56+
function __vsc_cmd_clear --on-event fish_cancel
57+
__vsc_esc D
58+
end
59+
60+
# Sent whenever a new fish prompt is about to be displayed.
61+
# Updates the current working directory.
62+
function __vsc_update_cwd --on-event fish_prompt
63+
__vsc_esc P "Cwd=$PWD"
64+
end
65+
66+
# Sent at the start of the prompt.
67+
# Marks the beginning of the prompt (and, implicitly, a new line).
68+
function __vsc_fish_prompt_start
69+
__vsc_esc A
70+
end
71+
72+
# Sent at the end of the prompt.
73+
# Marks the beginning of the user's command input.
74+
function __vsc_fish_cmd_start
75+
__vsc_esc B
76+
end
77+
78+
# Preserve the user's existing prompt, and wrap it in our escape sequences.
79+
functions --copy fish_prompt __vsc_fish_prompt
80+
81+
function fish_prompt
82+
__vsc_fish_prompt_start
83+
__vsc_fish_prompt
84+
__vsc_fish_cmd_start
85+
end

0 commit comments

Comments
 (0)