Skip to content

endowdly/tuliPS

Repository files navigation

tuliPS

tuliPS wraps Out-Default to provide a way to customize and colorize PowerShell outputs easily. tuliPS injects custom formatting functions into Out-Default and allows for powerful customization.

Features:

  • Colorize FileInfo and DirectoryInfo objects
  • Colorize MatchInfo objects
  • Display the targets of symbolic links and directory junction points
  • A human-readable and straight forward config file devoid of regex
  • Easy saving and loading of settings
  • Supports custom user extensions that can format any* object

Installation

Since this is a rough idea that could use polishing, it is not published anywhere. I will provide build zips on the releases page.

In general, clone this repository and run nova.bat. Select D to run the Default task, which will build the module and install it into the local modules directory.

Manual Build

Run build.bat and install the module in the Output directory to a location of your choosing.

Other Tasks

Alternatively, call Nova directly

& nova.ps1 -Task Default   # or whichever task you'd like

Usage

After the module is installed somewhere in the module path, just import the module.

Import-Module tuliPS

# Change the settings
Set-Tulips -AddExtensionSet Media -ForegroundColor Yellow -BackgroundColor Black -Extensions '.jpg', '.png'

# Save the settings
Export-Tulips ~/tulips.xml

# Load the settings
Import-Tulips ~/tulips.xml

Custom Formatters

Format any* object of your choosing. You can set one formatter per Type.

Keep the following two tips in mind:

  1. You must pass the object as the current object in the pipe with $_ or $PSItem, else the object will get stuck in limbo
  2. You must somehow write the object to the host, or you won't see it; Write-Host and the Console methods are you friends

Remember, tuliPS uses Out-Default, so how you see an object presented in the console is not how the object will be passed to stdout or to the pipe.

Tips:

  • Keep your types to singular types, that is, don't try to process string[]!
  • Use Set-TulipsFormatter to overwrite type formatters
  • The format operator, -f, is your friend
# Easy example.
Add-TulipsFormatter -Type System.String -Scriptblock { Write-Host $_ -ForegroundColor Red }

# Simple types can be infered.
Add-TulipsFormatter Int { '{0:P}' -f $_ | Write-Host }

# You can use your own complex functions.
Add-TulipsFormatter System.Diagnostics.Process { Format-MyProcess $_ }   # Just be sure Format-MyProcess isn't private 

Background

Microsoft Consoles did not support Virtual Terminal (VT) ANSI escape sequences for color output support. Combining ANSI sequences with the PowerShell type formatting (format.ps1xml) allows for very powerful control over formatting. Check out DirColors by Dustin Howett for a fantastic example.

However, I hate ANSI escape sequences and virtual terminal support for it. It's ancient. It's clunky. It's hard to read. And it needs an update. Why are we still using old hardware codes for hardware that doesn't exist to tell modern software what to do?

This is my attempt at an easily configurable color formatter for Out-Default that doesn't use regex or escape codes.

Screenshots

tuliPS ls listing

tuliPS match listing

tulips custom format

Credit

Inspiration by David Lindblad (PSColor) and David Howett (DirColors). Credit also to Kevin Marquette for pieces of his (old) versioning system and build script ideas.


* I haven't tested custom PSObjects that are given a defined type name or PSClasses yet
Last Updated: 2019-03-12T10:05:32.1875582-04:00