Home

Awesome

pure-pwsh

PowerShell implementation of the pure prompt.

Loads git status information asynchronously so that the prompt doesn't block and is able to update the prompt in response to file system changes without any user interation.

summary

Dependencies

Installation

Install from the gallery or clone this repository

Install-Module pure-pwsh

and import it in your profile. If you use this with posh-git (e.g. for its excellent Git completion) then you'll probably want to import pure-pwsh first so that posh-git doesn't spend time configuring its own prompt.

# ~/Documents/PowerShell/Microsoft.PowerShell_profile.ps1

Import-Module pure-pwsh
Import-Module posh-git

Options

Set options on the $pure global.

OptionDescriptionDefault value
PwdColorCurrent directory name colour<img src="https://placehold.it/18/0000aa?text=+"/>
BranchColorCurrent branch name colour<img src="https://placehold.it/18/6c6c6c?text=+"/>
DirtyColorGit dirty marker colour<img src="https://placehold.it/18/ffafd7?text=+"/>
RemoteColorRemote status colour (up/down arrows)<img src="https://placehold.it/18/00aaaa?text=+"/>
ErrorColorError prompt color<img src="https://placehold.it/18/aa0000?text=+"/>
PromptColorColour of the main prompt<img src="https://placehold.it/18/aa00aa?text=+"/>
TimeColorColour used for command timings<img src="https://placehold.it/18/ffff00?text=+"/>
UserColorColour of user & hostname in SSH<img src="https://placehold.it/18/6c6c6c?text=+"/>
SlowCommandTimeDuration at which command is 'slow'00:05
FetchIntervalInterval at which to fetch from remotes05:00
PromptCharPrompt character
UpCharUp arrow
DownCharDown arrow
PendingCharShown during git status update
WindowTitleCustomise the window title{ $PWD.Path.Replace($HOME, '~')}
BranchFormatterCustomize format of git branch name{ $args }
PwdFormatterCustomize format of working dir name{ $PWD.Path.Replace($HOME, '~')}
PrePromptCustomize the line above the prompt{ param ($user, $cwd, $git, $slow) … }

Compatibility

pure-pwsh should work anywhere PowerShell 7 does, including Windows, Mac, and Linux. Due to a longstanding bug in PSReadLine, async updates may not be scheduled on Mac and Linux until you interact with the console in some way.

Not currently included

Consider raising an issue if you want any of the above, or use one of the recipes below.

Recipes

Shorten path segments

Abbreviate each segment of the current path except for the leaf node.

abbreviated-path

$pure.PwdFormatter = {
  (
    ((Split-Path $pwd).Replace($HOME, '~').Split($pwd.Provider.ItemSeparator) |% {$_[0]}) +
    (Split-Path -Leaf $pwd)
  ) -join '/'
}

Truncate branch name

Truncate the branch name to a maximum of 12 characters.

truncate branch

$pure.BranchFormatter = {
  param ($n)
  $n.Length -lt 12 ? $n : ($n[0..11] -join '') + '…'
}

Show git stash indicator

stash indicator

$pure.PrePrompt = {
  param ($user, $cwd, $git, $slow)
  "`n$user{0}$cwd $git{1}$slow `n" -f($user ? ' ' : ''), ((git stash list) ? ' ≡ ' : '')
}

Show Python virtual env

stash indicator

$pure.PrePrompt = {
    param ($user, $cwd, $git, $slow)
    "`n$user{1}{0}$cwd $git $slow `n" -f
    ($user ? ' ' : ''),
    (($ve = $env:virtual_env) ? "$($pure._branchcolor)($(Split-Path -Leaf $ve)) " : "" )
}

One line prompt

stash indicator

$pure.UserColor = '38;5;242;4'

$pure.PrePrompt = {
  param ($user, $cwd, $git, $slow)
  $seperator = $pure._branchcolor +  " ❯ "
  "`n$user{0}$cwd{1}$git$slow " -f
    ($user ? $seperator : ''),
    ($git ? $seperator : '')
}

Use a different colour for user and hostname parts

stash indicator

$pure.UserFormatter = { param ($ssh, $user, $hostname) $ssh ? "$user`e[32m@$hostname" : '' }