From 4e3423ebfbae33888b75fd7374ae70d778683f41 Mon Sep 17 00:00:00 2001 From: Ocean <51983215+ocean-sudo@users.noreply.github.com> Date: Sat, 23 Aug 2025 22:26:35 +0800 Subject: [PATCH 1/2] Add shell integration instructions for Fish Shell --- TerminalDocs/tutorials/shell-integration.md | 74 +++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/TerminalDocs/tutorials/shell-integration.md b/TerminalDocs/tutorials/shell-integration.md index 0bd6477b..0f1fd885 100644 --- a/TerminalDocs/tutorials/shell-integration.md +++ b/TerminalDocs/tutorials/shell-integration.md @@ -16,6 +16,7 @@ ms.topic: tutorial - [PowerShell (`pwsh.exe`)](#powershell-pwshexe) - [Command Prompt](#command-prompt) - [Bash](#bash) + - [Fish](#fish) - [Shell integration features](#shell-integration-features) - [Open new tabs in the same working directory](#open-new-tabs-in-the-same-working-directory) - [Show marks for each command in the scrollbar](#show-marks-for-each-command-in-the-scrollbar) @@ -317,6 +318,79 @@ bash-5.2$ echo "|${PS1}|" bash-5.2$ echo "|${PS2}|" || ``` +# Fish +For the fish shell, you can enable shell integration by creating a new file, for example ~/.config/fish/conf.d/wt_integration.fish, and adding the following script. + +This script leverages fish's event system to automatically send the necessary shell integration sequences. It is designed to be robust, only activating when in an interactive session within Windows Terminal (by checking for the $WT_SESSION variable). It also includes a specific function to correctly report the current working directory when running under WSL by using wslpath. + +Add the following to your ~/.config/fish/conf.d/wt_integration.fish file: +```fish +# Only activate in an interactive session running inside Windows Terminal +if status --is-interactive; and set -q WT_SESSION + + # Define the FTCS (Final Term Command Sequences) for shell integration + set -g __fish_wt_prompt_start (printf "\e]133;A\e\\") + set -g __fish_wt_prompt_end (printf "\e]133;B\e\\") + set -g __fish_wt_cmd_executed (printf "\e]133;C\e\\") + set -g __fish_wt_cmd_finished_pre (printf "\e]133;D;") + set -g __fish_wt_cmd_finished_post (printf "\e\\") + + # Event handler: Fired before a command is executed. + # Sends the "Command Executed" sequence. + function __fish_wt_preexec --on-event fish_preexec + printf '%s' $__fish_wt_cmd_executed + end + + # Event handler: Fired after a command has finished. + # Sends the "Command Finished" sequence with the command's exit status. + function __fish_wt_postexec --on-event fish_postexec + printf '%s%s%s' $__fish_wt_cmd_finished_pre $status $__fish_wt_cmd_finished_post + end + + # Event handler: Fired before the prompt is displayed. + # Updates the terminal's current working directory (CWD). + # Uses wslpath to translate WSL paths to Windows paths for compatibility. + function __fish_wt_update_cwd --on-event fish_prompt + printf "\e]9;9;\"%s\"\e\\" (wslpath -w (pwd)) + end + + # Overrides the default fish_prompt function to wrap it with FTCS sequences. + # This example shows a simple prompt. See below for a Starship example. + function fish_prompt + # Send "Prompt Start" sequence + printf '%s' $__fish_wt_prompt_start + + # --- YOUR PROMPT GENERATION LOGIC GOES HERE --- + # A basic example: + printf '%s@%s %s> ' (whoami) (hostname|cut -d . -f 1) (prompt_pwd) + + # Send "Prompt End" (or "Command Start") sequence + printf '%s' $__fish_wt_prompt_end + end + +end +``` +#### Starship Setup +If you are using Starship as your prompt, you will need to modify the fish_prompt function to wrap the starship command. This ensures Starship's output is correctly placed between the start and end prompt markers. + +Replace the fish_prompt function from the script above with the following: +```fish +function fish_prompt + set -l last_status $status + # Get the number of background jobs + set -l job_count (count (jobs -p)) + + # Send "Prompt Start" sequence + printf '%s' $__fish_wt_prompt_start + + # Render the Starship prompt and remove any trailing newlines + starship prompt --status=$last_status --jobs=$job_count | tr -d "\n" + + # Send "Prompt End" (or "Command Start") sequence + printf '%s' $__fish_wt_prompt_end +end +``` + > **Note**: > Don't see your favorite shell here? If you figure it out, feel free to [contribute a solution for your preferred shell!](https://github.com/MicrosoftDocs/terminal/compare) From 3c245e87b438849e2c10ed109bd6bfdee1986b56 Mon Sep 17 00:00:00 2001 From: Ocean <51983215+ocean-sudo@users.noreply.github.com> Date: Sat, 23 Aug 2025 22:31:02 +0800 Subject: [PATCH 2/2] Add shell integration instructions for Fish Shell --- TerminalDocs/tutorials/shell-integration.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TerminalDocs/tutorials/shell-integration.md b/TerminalDocs/tutorials/shell-integration.md index 0f1fd885..17f03734 100644 --- a/TerminalDocs/tutorials/shell-integration.md +++ b/TerminalDocs/tutorials/shell-integration.md @@ -318,7 +318,7 @@ bash-5.2$ echo "|${PS1}|" bash-5.2$ echo "|${PS2}|" || ``` -# Fish +### Fish For the fish shell, you can enable shell integration by creating a new file, for example ~/.config/fish/conf.d/wt_integration.fish, and adding the following script. This script leverages fish's event system to automatically send the necessary shell integration sequences. It is designed to be robust, only activating when in an interactive session within Windows Terminal (by checking for the $WT_SESSION variable). It also includes a specific function to correctly report the current working directory when running under WSL by using wslpath.