Skip to content

Commit

Permalink
Merge pull request microsoft#157291 from zgracem/fish-shell-integration
Browse files Browse the repository at this point in the history
add shell integration script for fish
  • Loading branch information
Tyriar authored Aug 9, 2022
2 parents 1141808 + 36e2df6 commit a7f9339
Show file tree
Hide file tree
Showing 7 changed files with 94 additions and 1 deletion.
1 change: 1 addition & 0 deletions build/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ module.exports.copyrightFilter = [
'!**/*.xml',
'!**/*.sh',
'!**/*.zsh',
'!**/*.fish',
'!**/*.txt',
'!**/*.xpm',
'!**/*.opts',
Expand Down
2 changes: 2 additions & 0 deletions build/gulpfile.reh.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,14 @@ const serverResources = [
'out-build/vs/base/node/ps.sh',

// Terminal shell integration
'out-build/vs/workbench/contrib/terminal/browser/media/shellIntegration.fish',
'out-build/vs/workbench/contrib/terminal/browser/media/shellIntegration.ps1',
'out-build/vs/workbench/contrib/terminal/browser/media/shellIntegration-bash.sh',
'out-build/vs/workbench/contrib/terminal/browser/media/shellIntegration-env.zsh',
'out-build/vs/workbench/contrib/terminal/browser/media/shellIntegration-profile.zsh',
'out-build/vs/workbench/contrib/terminal/browser/media/shellIntegration-rc.zsh',
'out-build/vs/workbench/contrib/terminal/browser/media/shellIntegration-login.zsh',
'out-build/vs/workbench/contrib/terminal/browser/media/shellIntegration.fish',

'!**/test/**'
];
Expand Down
1 change: 1 addition & 0 deletions build/gulpfile.vscode.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ const vscodeResources = [
'out-build/vs/workbench/browser/media/*-theme.css',
'out-build/vs/workbench/contrib/debug/**/*.json',
'out-build/vs/workbench/contrib/externalTerminal/**/*.scpt',
'out-build/vs/workbench/contrib/terminal/browser/media/*.fish',
'out-build/vs/workbench/contrib/terminal/browser/media/*.ps1',
'out-build/vs/workbench/contrib/terminal/browser/media/*.sh',
'out-build/vs/workbench/contrib/terminal/browser/media/*.zsh',
Expand Down
2 changes: 2 additions & 0 deletions src/vs/code/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ export async function main(argv: string[]): Promise<any> {
case 'pwsh': file = 'shellIntegration.ps1'; break;
// Usage: `[[ "$TERM_PROGRAM" == "vscode" ]] && . "$(code --locate-shell-integration-path zsh)"`
case 'zsh': file = 'shellIntegration-rc.zsh'; break;
// Usage: `string match -q "$TERM_PROGRAM" "vscode"; and . (code --locate-shell-integration-path fish)`
case 'fish': file = 'shellIntegration.fish'; break;
default: throw new Error('Error using --locate-shell-integration-path: Invalid shell type');
}
console.log(join(dirname(FileAccess.asFileUri('', require)).fsPath, 'out', 'vs', 'workbench', 'contrib', 'terminal', 'browser', 'media', file));
Expand Down
2 changes: 1 addition & 1 deletion src/vs/platform/environment/node/argv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ export const OPTIONS: OptionDescriptions<Required<NativeParsedArgs>> = {
'logsPath': { type: 'string' },
'__enable-file-policy': { type: 'boolean' },
'editSessionId': { type: 'string' },
'locate-shell-integration-path': { type: 'string', args: ['bash', 'pwsh', 'zsh'] },
'locate-shell-integration-path': { type: 'string', args: ['bash', 'pwsh', 'zsh', 'fish'] },

// chromium flags
'no-proxy-server': { type: 'boolean' },
Expand Down
2 changes: 2 additions & 0 deletions src/vs/server/node/server.cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ export async function main(desc: ProductDescription, args: string[]): Promise<vo
case 'pwsh': file = 'shellIntegration.ps1'; break;
// Usage: `[[ "$TERM_PROGRAM" == "vscode" ]] && . "$(code --locate-shell-integration-path zsh)"`
case 'zsh': file = 'shellIntegration-rc.zsh'; break;
// Usage: `string match -q "$TERM_PROGRAM" "vscode"; and . (code --locate-shell-integration-path fish)`
case 'fish': file = 'shellIntegration-fish.fish'; break;
default: throw new Error('Error using --locate-shell-integration-path: Invalid shell type');
}
console.log(resolve(__dirname, '../..', 'workbench', 'contrib', 'terminal', 'browser', 'media', file));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# ---------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# ---------------------------------------------------------------------------------------------
#
# Visual Studio Code terminal integration for fish
#
# Manual installation:
#
# (1) Add the following to the end of `$__fish_config_dir/config.fish`:
#
# string match -q "$TERM_PROGRAM" "vscode"
# and . (code --locate-shell-integration-path fish)
#
# (2) Restart fish.

# Don't run in scripts, other terminals, or more than once per session.
status is-interactive
and string match --quiet "$TERM_PROGRAM" "vscode"
and ! set --query VSCODE_SHELL_INTEGRATION
or exit

set --global VSCODE_SHELL_INTEGRATION 1

# Helper function
function __vsc_esc -d "Emit escape sequences for VS Code shell integration"
builtin printf "\e]633;%s\007" (string join ";" $argv)
end

# Sent right before executing an interactive command.
# Marks the beginning of command output.
function __vsc_cmd_executed --on-event fish_preexec
__vsc_esc C
__vsc_esc E (__vsc_escape_cmd "$argv")
end


# Escapes backslashes, newlines, and semicolons to serialize the command line.
function __vsc_escape_cmd
set -l commandline "$argv"
# `string replace` automatically breaks its input apart on any newlines.
# Then `string join` at the end will bring it all back together.
string replace --all '\\' '\\\\' $commandline \
| string replace --all ';' '\x3b' \
| string join '\x0a'
end
# Sent right after an interactive command has finished executing.
# Marks the end of command output.
function __vsc_cmd_finished --on-event fish_postexec
__vsc_esc D $status
end
# Sent when a command line is cleared or reset, but no command was run.
# Marks the cleared line with neither success nor failure.
function __vsc_cmd_clear --on-event fish_cancel
__vsc_esc D
end
# Sent whenever a new fish prompt is about to be displayed.
# Updates the current working directory.
function __vsc_update_cwd --on-event fish_prompt
__vsc_esc P "Cwd=$PWD"
end
# Sent at the start of the prompt.
# Marks the beginning of the prompt (and, implicitly, a new line).
function __vsc_fish_prompt_start
__vsc_esc A
end
# Sent at the end of the prompt.
# Marks the beginning of the user's command input.
function __vsc_fish_cmd_start
__vsc_esc B
end

# Preserve the user's existing prompt, and wrap it in our escape sequences.
functions --copy fish_prompt __vsc_fish_prompt

function fish_prompt
__vsc_fish_prompt_start
__vsc_fish_prompt
__vsc_fish_cmd_start
end

0 comments on commit a7f9339

Please sign in to comment.