themes/jaykul.ps1

# A plain old default prompt with some framework in place to make your own snazzier version

# Very basic prompt without git integration but with some conemu detection. Fast and stable.
function global:prompt {
    $realCommandStatus = $?
    $realLASTEXITCODE = $LASTEXITCODE

    # Customize any of these if you like
    $DefaultPromptPrefix = 'PS '
    $PromptSuffix = '> ' #[char]::ConvertFromUtf32(8594)
    $LastCommandSuccessForeground = $Host.UI.RawUI.ForegroundColor
    $LastCommandErrorForeground = if ($null -ne $host.PrivateData.ErrorForegroundColor) {$host.PrivateData.ErrorForegroundColor} else {'Red'}

    # If stopped in the debugger, the prompt needs to indicate that in some fashion
    $hasInBreakpoint = [runspace]::DefaultRunspace.Debugger | Get-Member -Name InBreakpoint -MemberType property
    $debugMode = (Test-Path Variable:/PSDebugContext) -or ($hasInBreakpoint -and [runspace]::DefaultRunspace.Debugger.InBreakpoint)
    $PromptPrefix = if ($debugMode) { 'DEBUG ' } else { $DefaultPromptPrefix }

    # Finally, pull our current location
    $loc = Get-Location

    # File system paths are case-sensitive on Linux and case-insensitive on Windows and macOS
    if (($PSVersionTable.PSVersion.Major -ge 6) -and $IsLinux) {
        $stringComparison = [System.StringComparison]::Ordinal
    }
    else {
        $stringComparison = [System.StringComparison]::OrdinalIgnoreCase
    }

    # Based on provider we can shorten or do other things to our output
    switch ($loc.Provider.Name) {
        'FileSystem' {
            # Shorten the file path a bit if possible
            # Abbreviate path by replacing beginning of path with ~ *iff* the path is in the
            # user's home dir
            if ($($loc.ProviderPath).StartsWith($Home, $stringComparison)) {
                $ThisPath = "~" + $($loc.ProviderPath).SubString($Home.Length)
            }
            else {
                $ThisPath = $loc.ProviderPath
            }
            #$ThisPath = ($loc.ProviderPath -replace $([Regex]::Escape((Convert-Path '~'))),'~')
        }
        Default {
            $ThisPath = $loc.Path
        }
    }

    if ($realCommandStatus) {
        $PromptColor = $LastCommandSuccessForeground
    }
    else {
        $PromptColor = $LastCommandErrorForeground
    }

    # Maybe you can use this, maybe you don't care though so just leaving it commented out.
    try {
        $Elevated = Test-OMPIsElevated
    }
    catch {}

    if ($Elevated) {
        Set-OMPWindowTitle -Title ("{0} - {1} ({2})" -f ("PS $($PSVersionTable.PSVersion.Major) - ${Env:UserName}@${Env:UserDomain} (ADMIN)",$pwd.Path,$pwd.Provider.Name))
    }
    else {
        Set-OMPWindowTitle -Title ("{0} - {1} ({2})" -f ("PS $($PSVersionTable.PSVersion.Major) - ${Env:UserName}@${Env:UserDomain}",$pwd.Path,$pwd.Provider.Name))
    }

    # Other modules can mess with the foreground color, this sometimes fixes that (temporarily)
    $Host.UI.RawUI.ForegroundColor = $Host.UI.RawUI.ForegroundColor

    # Determine what nesting level we are at (if any)
    $Nesting = "$([char]0xB7)" * $NestedPromptLevel

    # Generate PUSHD(push-location) Stack level string
    $Stack = "+" * (Get-Location -Stack).count

    # Notice: no angle brackets, makes it easy to paste my buffer to the web
    Write-Host "$([char]9556)" -NoNewLine -Foreground $PromptColor
    Write-Host " $(if($Nesting){"$Nesting "})#$($MyInvocation.HistoryID)${Stack} " -Foreground $PromptColor -NoNewLine
    Write-Host "$PromptPrefix$ThisPath" -NoNewLine -ForegroundColor $PromptColor
    Write-OMPGitStatus
    Write-Host ' '
    Write-Host "$([char]9562)$([char]9552)$([char]9552)$([char]9552)$([char]9557)" -Foreground $PromptColor -NoNewLine

    $global:LASTEXITCODE = $realLASTEXITCODE

    # Simple check for ConEmu existance and ANSI emulation enabled
    if ($env:ConEmuANSI -eq 'ON') {
        # Let ConEmu know when the prompt ends, to select typed
        # command properly with "Shift+Home", to change cursor
        # position in the prompt by simple mouse click, etc.
        $PromptSuffix += "$([char]27)]9;12$([char]7)"

        # And current working directory (FileSystem)
        # ConEmu may show full path or just current folder name
        # in the Tab label (check Tab templates)
        # Also this knowledge is crucial to process hyperlinks clicks
        # on files in the output from compilers and source control
        # systems (git, hg, ...)
        if ($loc.Provider.Name -eq 'FileSystem') {
            $PromptSuffix += "$([char]27)]9;9;`"$($loc.Path)`"$([char]7)"
        }
    }
    if (-not $promptSuffix) {
        $promptSuffix = ' '
    }

    $PromptSuffix
}