It's a simple script containing few useful utils that help in creating custom, pretty and fully flexible Powershell prompts. If you don’t want to write too much code yourself, I would recommend you using one of the existing solutions that work out of the box (for example this one).
But if you want to create a fully custom and tailor made prompt, feel free to fork this repo and adjust it to your needs.
- Get yourself a modern terminal (for example the Windows Terminal).
- Install a font the supports powerline characters (for example the CascadiaMonoPL.ttf) and set it as the default font of your terminal.
- Open (or create) your Powershell profile file (on how to do it).
- Paste the content of the profile.ps1 script at the end of your profile file.
- Customize the behavior of the script based on your personal needs.
The profile.ps1
script defines two useful classes: Color
and PromptBuilder
. Everything after that is me using those classes to customize my own prompt. The customization code contains few hardcoded paths from my environment, so you will definitely want to rewrite it. Nevertheless, it can be a good starting point for experimentations and a nice learning example on how to use this script.
The idea here is simple:
- Create an instance of the
PromptBuilder
class. - Call the
WithSection
method to append new a block at the end of the prompt. TheWriteSection
method allows you to specify the background color of the new section. - Call the
WithSeparator
method (or theWithReversedSeparator
depending on the direction the separator is facing) to add the powerline separator between sections. You have to call it between theWithSection
calls. The foreground and background color of the separator will be derived from neighboring sections. - Get the complete string by calling the
ToString
method of thePromptBuilder
and return it from theprompt
function
The list of powerline character codes can be bound here.