Giter Club home page Giter Club logo

tulips's Introduction

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

tulips's People

Contributors

endowdly avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.