From e3446316fde3acf789b770a774efc04419235d4d Mon Sep 17 00:00:00 2001 From: Peter Wagner Sandoval Moreno Date: Mon, 13 Mar 2023 19:26:34 -0500 Subject: [PATCH] Add function for users powershell + starship References: Similar script for wt https://learn.microsoft.com/en-us/windows/terminal/tutorials/new-tab-same-directory#powershell-with-posh-git Custom pre-prompt in starship https://starship.rs/advanced-config/#custom-pre-prompt-and-pre-execution-commands-in-powershell --- docs/shell-integration.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/shell-integration.md b/docs/shell-integration.md index 5e2f2277d..533432d00 100644 --- a/docs/shell-integration.md +++ b/docs/shell-integration.md @@ -128,6 +128,21 @@ function prompt { } ``` +### OSC 7 on Windows with powershell (with starship) + +When you're using [Starship](https://starship.rs/), the prompt is already modify, in this case can add only the necessary output to the already modified prompt, with a function like this in [powershell profile](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-7.1): + +```powershell +$prompt = "" +function Invoke-Starship-PreCommand { + $current_location = $executionContext.SessionState.Path.CurrentLocation + if ($current_location.Provider.Name -eq "FileSystem") { + $provider_path = $current_location.ProviderPath -replace "\\", "/" + $prompt = "$ansi_escape]7;file://${env:COMPUTERNAME}/${provider_path}$ansi_escape\" + } + $host.ui.Write($prompt) +```` + ## Using Clink on Windows Systems [Clink](https://github.com/chrisant996/clink) brings bash style line editing,