pure-pwsh
July 19, 2020 · View on GitHub
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.
Dependencies
- Terminal with ANSI colour support
- PowerShell 7.0+
- Git 2.0+ on your path
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.
| Option | Description | Default value |
|---|---|---|
PwdColor | Current directory name colour | |
BranchColor | Current branch name colour | |
DirtyColor | Git dirty marker colour | |
RemoteColor | Remote status colour (up/down arrows) | |
ErrorColor | Error prompt color | |
PromptColor | Colour of the main prompt | |
TimeColor | Colour used for command timings | |
UserColor | Colour of user & hostname in SSH | |
SlowCommandTime | Duration at which command is 'slow' | 00:05 |
FetchInterval | Interval at which to fetch from remotes | 05:00 |
PromptChar | Prompt character | ❯ |
UpChar | Up arrow | ⇡ |
DownChar | Down arrow | ⇣ |
PendingChar | Shown during git status update | ⋯ |
WindowTitle | Customise the window title | { $PWD.Path.Replace($HOME, '~')} |
BranchFormatter | Customize format of git branch name | { $args } |
PwdFormatter | Customize format of working dir name | { $PWD.Path.Replace($HOME, '~')} |
PrePrompt | Customize 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
- No vi mode indicator
- No git stash indicator
- No git action indicator (rebase, cherry pick, etc.)
- No python virtual env indicator
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.
$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.
$pure.BranchFormatter = {
param ($n)
$n.Length -lt 12 ? $n : ($n[0..11] -join '') + '…'
}
Show git 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
$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
$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
$pure.UserFormatter = { param ($ssh, $user, $hostname) $ssh ? "$user`e[32m@$hostname" : '' }