PowerShell prompts

In PowerShell, you modify your shell prompt by defining a function called prompt, generally in your profile.ps1 file (or wherever $PROFILE.CurrentUserAllHosts points to). Its return value is used as your prompt. I've spent a fair amount of time tinkering with mine, but currently there's nothing particularly special there, just the current time, path, and information about the Git repository the current path is part of, if applicable (courtesy of posh-git).

One thing I'm not entirely happy about here is that the path is sometimes far to long, and won't even fit within the width of my shell window. I'd like to find a way to truncate it if it's above a certain length, but haven't spent much time on this problem yet.

Import-Module posh-git

New-Alias which Get-Command
...
function prompt {
    $(if (Test-Path variable:/PSDebugContext) { '[DBG]: ' }
        else { '' }) + 
        "($(Get-Date -Format 'H:m:ss')) " +
        $(if ($NestedPromptLevel -ge 1) { '>>' }) + 
        $(Get-Location).Path + 
        $(Write-VcsStatus) +
        '> '
}

About Me

Developer at Brown University Library specializing in instructional design and technology, Python-based data science, and XML-driven web development.