Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a PowerShell code formatter / pretty printer? [closed]

I'm looking for a source code beautifyer for PowerShell programs. Ideally, it would be CLI based, but any solution is acceptable. I would like to avoid configuring a generic pretty printer tool; I'd like a solution that works for PowerShell out of the box. Is there such a thing?

like image 903
Sleepless Avatar asked Jun 07 '10 05:06

Sleepless


People also ask

How do I use AutoSize in PowerShell?

If you specify the AutoSize parameter when you run the Format-Table command, PowerShell calculates column widths based on the actual data displayed. This makes the columns readable. The Format-Table cmdlet might still truncate data, but it only truncates at the end of the screen.

How do I display output in a Table Format in PowerShell?

The Format-Table cmdlet formats the output of a command as a table with the selected properties of the object in each column. The object type determines the default layout and properties that are displayed in each column. You can use the Property parameter to select the properties that you want to display.

What is FL in PowerShell?

Format-List, or FL for short, allows PowerShell to control the output of your main script. Whenever presentation of information is important, pipe the script's output into Format-List (or Format-Table).


2 Answers

UPDATE: it's now on GitHub: https://github.com/DTW-DanWard/PowerShell-Beautifier

I wrote a PowerShell pretty printer / code cleaner in PowerShell. It cleans white space, indents code groups, replaces aliases with commands, fixes casing on commands, parameters, types, etc. You can use it to reformat a file in place or read a source file and output the result in a different file.

More info: http://danspowershellstuff.blogspot.com/2012/03/powershell-pretty-printer-code-cleaner.html

Download page: http://www.dtwconsulting.com/PS/Module_PrettyPrinterV1.htm

Let me know what you'd like to see changed/configurable/etc.

like image 173
DanW Avatar answered Oct 08 '22 17:10

DanW


I don't know of any. However, PowerShell V2 exposes a PowerShell tokenizer you could build on: System.Management.Automation.PsParser

It might be interesting to do some "lint"-like checks, too.

For example, I think scripts should avoid using aliases that aren't marked ReadOnly, as users may have changed them. See Where are the default aliases defined in powershell? for some discussion.

like image 35
Jay Bazuzi Avatar answered Oct 08 '22 16:10

Jay Bazuzi