Skip to content

Instantly share code, notes, and snippets.

@falkheiland
Last active November 1, 2020 11:03
Show Gist options
  • Save falkheiland/038e33f01d0768386a94ef6676241dc4 to your computer and use it in GitHub Desktop.
Save falkheiland/038e33f01d0768386a94ef6676241dc4 to your computer and use it in GitHub Desktop.
PowerShell Microsoft.VSCode_profile.ps1
Import-Module -Name posh-git
$GitPromptSettings.EnableWindowTitle = $false
function Prompt
{
try
{
if (($PSEdition -eq 'Core' -and $IsWindows) -or ($PSEdition -eq 'Desktop' -and ($PSVersionTable.PSVersion.Major -eq 5 -and $PSVersionTable.PSVersion.Minor -eq 1)))
{
# PS7 on Windows or Windows PowerShell 5.1
$host.ui.RawUI.WindowTitle = 'Windows | {0} {1}' -f $PSVersionTable.PSVersion.ToString(), ($PSVersionTable.PSEdition)
}
elseif ($PSEdition -eq 'core' -and (-Not $IsWindows) )
{
# PS7 on Linux OR MacOS
$Uname = uname
$host.ui.RawUI.WindowTitle = '{0} | {1} {2}' -f $Uname, $PSVersionTable.PSVersion.ToString(), ($PSVersionTable.PSEdition)
}
Write-Host '[' -NoNewline
Write-Host ([DateTime]::now.ToString('HH:mm:ss')) -NoNewline -ForegroundColor Yellow
Write-Host '] ' -NoNewline
$History = Get-History -ErrorAction Ignore -Count 1
if ($History)
{
Write-Host '[' -NoNewline
$TimeSpan = New-TimeSpan -Start $History.StartExecutionTime -End $History.EndExecutionTime
switch ($TimeSpan)
{
{ $_.TotalSeconds -lt 1 }
{
[int]$d = $_.TotalMilliseconds
'{0}ms' -f ($d) |
Write-Host -ForegroundColor Black -NoNewline -BackgroundColor DarkGreen
break
}
{ $_.totalminutes -lt 1 }
{
[int]$d = $_.TotalSeconds
'{0}s' -f ($d) |
Write-Host -ForegroundColor Black -NoNewline -BackgroundColor DarkYellow
break
}
{ $_.totalminutes -ge 1 }
{
"{0:HH:mm:ss}" -f ([datetime]$TimeSpan.Ticks) |
Write-Host -ForegroundColor Gray -NoNewline -BackgroundColor Red
break
}
}
Write-Host ']' -NoNewline
}
Write-Host '[' -NoNewline
Write-Host "$($PWD.path)" -NoNewline
Write-Host ']' -NoNewline
if (Get-Module Posh-git)
{
Write-VcsStatus
Write-Host ''
}
'# '
}
catch
{
Write-Error $_.Exception.Message
}
}
function Google
{
Start-Process "https://www.google.com/search?q=powershell+$args"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment