Skip to content

PowerShell implementation of the pure prompt

License

Notifications You must be signed in to change notification settings

ksawerykarwacki/pure-pwsh

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pure-pwsh

PowerShell implementation of the pure prompt.

Dependencies

  • Terminal with ANSI colour support (e.g. any modern version of Windows 10, ConEmu, Hyper, ansicon, etc.)
  • PSReadLine for async prompt updates. Works best with PSReadLine 2.0.

Options

Set options on the $pure global.

Option Description Default value
PwdColor Colour of the current directory name.
BranchColor Colour of the current branch name.
RemoteColor Colour of remote status (up/down arrows).
ErrorColor Colour of error prompt and slow commands.
PromptColor Colour of the main prompt.
PromptChar Prompt character. (or on PSReadLine < 2.0)
UpChar Up arrow. (or on PSReadLine < 2.0)
DownChar Down arrow. (or on PSReadLine < 2.0)
SlowCommandTime Duration at which command is 'slow'. 00:05
FetchInterval Period at which to fetch from remotes. 05:00
BranchFormatter Customize format of git branch name. { $args }
PwdFormatter Customize format of working dir name. { param ($cwd) $cwd.Replace($HOME, '~') }
PrePrompt Customize the line above the prompt. { param ($cwd, $git, $slow) "`n$cwd $git $slow"`n }

To customise the formatting of the current git branch or working directory, provide a function that transforms a string parameter into a string output. For example, this truncates the branch name by underscore delimited segments:

$pure.BranchFormatter = {
     $args |% {
       @(((($_ -split '_' | select -First 3) -join '_') + '…'), $_)
     } | sort Length | select -First 1
}

Similarly, you can customise the entire upper line by providing a function that transforms three string parameters ($cwd, $git and $slow) into a string output. For example, to include your username before the directory info:

$pure.PrePrompt = {param ($cwd, $git, $slow) "`n$($pure._branchColor)$([Environment]::UserName) $cwd $git $slow`n"}

Or to put the entire prompt on one line, remove the `n at the end of the pre-prompt:

$pure.PrePrompt = {param ($cwd, $git, $slow) "`n$cwd $git $slow"}

Further customisations can be easily made, for example to color your username a unique color you can provide an ANSI escade code, as follows

myColours = @{ blue = "`e[38;5;31m" }

$pure.PrePrompt =
  {param ($cwd, $git, $slow) "`n$($myColours.blue)$([Environment]::UserName) $cwd $git $slow"}

which colors the username deep sky blue 3.

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 (recommended for its excellent command completion) then you'll probably want to import pure-pwsh first so that posh-git doesn't waste time configuring the prompt.

Import-Module pure-pwsh

Compatibility

The packaged dependencies are built for the Windows x64 platform. To build for an alternative platform, cd into the directory containing PurePwsh.csproj (i.e. $env:PSModulePath/pure-pwsh/[version]/pure-pwsh) and run:

dotnet publish -o bin -c Release -r [your-runtime] # https://docs.microsoft.com/en-us/dotnet/core/rid-catalog

Not currently included

  • Does not display username and host for remote sessions
  • Does not set window title
  • No vi mode indicator

Consider raising an issue if you want any of the above.

About

PowerShell implementation of the pure prompt

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 50.3%
  • PowerShell 49.7%