Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

show-syntax

A PowerShell module inspired by the popular Rust CLI tool bat — a cat clone with ANSI syntax highlighting. show-syntax reads files and outputs their contents to the console with colour-coded highlighting based on file extension, plus optional line numbers.


Features

  • 🎨 ANSI syntax highlighting for common file types: PowerShell, JSON, XML, Markdown, Python, JavaScript/TypeScript, YAML, Shell scripts, CSS, HTML, CSV, and log files
  • 🔢 Optional line numbers with -ShowLineNumbers
  • 🔧 Language override with -Language when auto-detection isn't enough
  • 📥 Pipeline support — pipe paths or FileInfo objects directly
  • 🛡️ Graceful error handling for missing or invalid paths
  • ⚡ Efficient streaming — reads files line-by-line via StreamReader to handle large files without loading everything into memory

Installation

show-syntax is published to the PowerShell Gallery.

# Install from PowerShell Gallery
Install-Module -Name show-syntax -Scope CurrentUser

# Import the module
Import-Module show-syntax

Requirements: PowerShell 5.1 or later (Windows PowerShell 5.1 and PowerShell 7+).


Usage

Example 1 — Display a PowerShell script with syntax highlighting

Show-Syntax -Path .\Deploy.ps1

Automatically detects the .ps1 extension and applies PowerShell highlighting (keywords, variables, strings, comments, and cmdlet names are all coloured).


Example 2 — Display a JSON file with line numbers

Show-Syntax -Path .\appsettings.json -ShowLineNumbers

Displays the file with JSON highlighting (keys, values, booleans, numbers) and prepends each line with its line number.


Example 3 — Pipe multiple files from Get-ChildItem

Get-ChildItem -Path .\src -Filter *.ps1 -Recurse | Show-Syntax -ShowLineNumbers

Pipes all .ps1 files found recursively under .\src into Show-Syntax, displaying each with a header banner, PowerShell highlighting, and line numbers.


Example 4 — Override language detection

Show-Syntax -Path .\Dockerfile -Language sh

Forces Shell/Bash highlighting on a file whose extension is unknown.


Example 5 — Pipe a single path as a string

'.\README.md' | Show-Syntax

Passes a file path string through the pipeline and displays it with Markdown highlighting.


Parameters

Parameter Type Required Description
-Path string[] ✅ One or more file paths. Accepts pipeline input by value or by property name (FullName, FilePath).
-ShowLineNumbers switch ❌ Prepends each output line with its 1-based line number.
-Language string ❌ Overrides auto-detection. See supported language keys below.

Supported -Language values

Key(s) File types
ps1, powershell PowerShell (.ps1, .psm1, .psd1)
json JSON
xml XML
md, markdown Markdown
py, python Python
js, javascript, ts, typescript JavaScript / TypeScript
yaml YAML
sh, bash Shell / Bash
css CSS / SCSS / Less
html HTML
csv CSV
log Log files
txt Plain text (no highlighting)

Running Tests

The module includes a Pester 5 test suite.

# Install Pester if not already installed
Install-Module Pester -MinimumVersion 5.0 -Scope CurrentUser -Force

# Run all tests
Invoke-Pester -Path .\show-syntax.Tests.ps1 -Output Detailed

Contributing

Contributions are welcome! Please open an issue or pull request on GitHub.


License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages