Last active
October 3, 2024 15:27
-
-
Save pitchinnate/890f5375f5e788f5a84b1b0bc399feab to your computer and use it in GitHub Desktop.
Powershell Starship update terminal title to directory and running command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # show directory as title, last 2 directories, can change by changing 2 to something else | |
| function Invoke-Starship-PreCommand { | |
| $current = ( $PWD -split '\\' | select -last 2 ) -join '\' | |
| $host.ui.RawUI.WindowTitle = "$current" | |
| } | |
| # normal starship invoke | |
| Invoke-Expression (&starship init powershell) | |
| # this must be put in after the invoke of starship | |
| # Set the console title to the currently running command | |
| Set-PSReadLineKeyHandler -Key Enter ` | |
| -BriefDescription RunWithTitle ` | |
| -LongDescription "Set the console title to the command, then run the command" ` | |
| -ScriptBlock { | |
| param($key, $arg) | |
| $line = $null | |
| $cursor = $null | |
| [Microsoft.PowerShell.PSConsoleReadLine]::GetBufferState([ref]$line, [ref]$cursor) | |
| $current = ( $PWD -split '\\' | select -last 1 ) -join '\' | |
| $Host.UI.RawUI.WindowTitle = "$line | $current" | |
| [Microsoft.PowerShell.PSConsoleReadLine]::AcceptLine() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment