Skip to content

lucaspimentel/pwsh-prompt

Repository files navigation

pwsh-prompt

A fast, customizable PowerShell prompt written in C# and compiled as a native AOT binary for instant startup.

Features

  • Lightning fast: Native AOT compilation means zero startup delay
  • Git integration: Shows current branch with smart caching
  • Path display: Intelligently truncates long paths to fit terminal width
  • Command feedback: Displays exit codes and execution duration
  • System info: Shows OS and shell information
  • Simple mode: Minimal prompt option for even faster rendering

Installation

Install from GitHub Release (Recommended)

No build tools or .NET SDK required:

irm https://raw.githubusercontent.com/lucaspimentel/pwsh-prompt/main/install-remote.ps1 | iex

Or to install a specific version:

$version = "1.0.0"; irm https://raw.githubusercontent.com/lucaspimentel/pwsh-prompt/main/install-remote.ps1 | iex

Install from Source

Clone the repository and run the installation script:

./install-local.ps1

This will build the native binary and install it to ~/.local/bin/pwsh-prompt.

Setup

Add this line to your PowerShell profile ($PROFILE):

Invoke-Expression (& ~/.local/bin/pwsh-prompt init)

Simple Mode

For a minimal prompt with just path, git, and host information:

# Edit the init output or modify your profile to use --simple
pwsh-prompt prompt --simple

Building Manually

# Quick build test
dotnet build src/pwsh-prompt -c Release -f net10.0

# Publish for Windows
dotnet publish src/pwsh-prompt -c Release -r win-x64 --output ./publish

# Publish for Linux
dotnet publish src/pwsh-prompt -c Release -r linux-x64 --output ./publish

# Or build via solution
dotnet build pwsh-prompt.slnx

Project Structure

pwsh-prompt/
├── src/
│   └── pwsh-prompt/          # Main C# project
│       ├── Modules/          # Segment implementations (ISegment)
│       ├── Program.cs        # Entry point and mode routing
│       ├── Arguments.cs      # Command-line argument parsing
│       ├── GitInfo.cs        # Git repository detection and caching
│       ├── Init.cs           # PowerShell initialization script generator
│       └── ...               # Other core files
├── install-local.ps1         # Build from source and install
├── install-remote.ps1        # Download from GitHub releases and install
└── pwsh-prompt.slnx          # Solution file

Architecture

The prompt uses a modular segment system where each visual element (path, git branch, exit code, etc.) implements the ISegment interface. The application runs in two modes:

  1. init mode: Generates PowerShell initialization code to install the prompt
  2. prompt mode: Renders the actual prompt on every invocation

Performance

Since this runs on every prompt render, performance is critical:

  • Native AOT compilation eliminates JIT overhead for instant startup
  • Environment variable caching avoids repeated git file I/O (cache invalidates on directory change or .git/HEAD modification)
  • Stack-allocated buffers minimize heap allocations via ValueStringBuilder
  • Smart truncation calculates exact widths for optimal path display

The PowerShell profile caches git information between prompts, avoiding file system operations when the branch hasn't changed.

License

MIT License - see LICENSE file for details.

Copyright (c) 2025 Lucas Pimentel

About

Custom PowerShell prompt inspired by Oh-My-Posh and Starship. Written in C#/.NET.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 3

  •  
  •  
  •