PowerShell script in one long line - auto-format? - powershell

I was given a PowerShell script, that when opened in a text editor, is one very long line of code. Is there any kind of auto-format tool for PowerShell syntax? I use Notepad++ and read a thread here (https://superuser.com/questions/58884/auto-format-document-with-notepad)and here (PowerShell Code Tidy or Reformat?) about certain plugins that can help with indentation and other code cleanup, but nothing that I've seen that can take one long line and tidy it.
Thanks.

I'd suggest using Visual Studio Code with the PowerShell extension. From there, you can utilize the Format Document tool (default keybind: SHIFT+ALT+F). This will look at your settings file and uses PSScriptAnalyzer to perform the formatting rules.
With the newest update (June2018), Visual Studio Code supports fully portable downloads by downloading the .zip option and creating the /data/tmp/ directory in the root where code.exe lives.
Visual Studio Code
PowerShell extension releases
Microsoft recommendations

Related

Visual Studio Code Love2D support extension detecting love.app as a directory

I have just started with löve because of an internet course I'm on, and I'm using Visual studio code as my editor. The course recommends that I use the "Love2D Support" extension with Visual Studio. It allows me to run the code directly from VS by pressing Command + L.
Although when I do it, VS outputs me this error:
The setting specified in pixelbyte.love2d.path must be an executable file, not a directory. Check your settings.
The path I have input in the settings is /Users/My_Username/Desktop/love.app
I am 100% sure that it is the correct directory. What is the problem?
Thanks for answering!
The actual executable file in Mac is /Applications/love.app/Contents/MacOS/love so put this in your pixelbyte.love2d.path command in vscode and you are good to go.

Powershell ISE variable highlighter

Is there any add-ons for Powershell ISE where you can highlight any occurrence of the variable or any word? Something like Sublime Text has?
The ISE doesn't have support for add-ons, but Visual Studio Code does (and there's lots of good ones). It also has much better built-in syntax highlighting and Git support (if Git is installed). You'll need to install the PowerShell extension from the "extension marketplace" (just search for "PowerShell"). Also, Microsoft has said that they're not planning to continue maintenance of ISE, so VS Code is probably what you should be using to write PowerShell.
The ISE was not highlighting any keywords/syntaxes, for me the issue was with the file extension, the PS script file extension was inadvertently set to .ps, when I renamed it to have .ps1 extension, all the syntax highlighting revived. Hope this helps others.

Using Powershell ISE's intellisense in other terminal

I'm a big fan of powershell ISE as a terminal. It has intellisense and syntax highlighting built in the shell and I just use it instead of the regular shell for everyday commands.
I would like to use Visual Studio Code instead, because the editor is much more powerfull and has support for a whole lot of languages and format. However the integrated shell is you basic Powershell terminal : no intellisense, no coloring (even with Powershell 5 installed on my computer).
Is there any way to add intellisense and coloring to my terminal, or use ISE's terminal in VSCode? or is there a plugin somewhere adressing these issues?
The integrated PowerShell terminal on Visual Studio Code does have intellisense, so I'm unclear what you require here, are you sure it's not set to cmd.exe instead ?
On another note, follow this setup guide. In case you haven't already installed the PowerShell Extension.

Run command line when a document is saved in Visual Studio 2013?

I'm currently evaluating using VS2013 for a HTML5 project.
In this project I would like to be able to run a command line tool every time a file is saved (and have the file path passed as argument to the command line tool), and then have the output displayed in the console in VS. It's also important that this setup can be part of the project file, so that when a developer opens the project it's already setup correctly and ready to go without any additional configuring in VS.
In both Sublime Text and Webstorm projects all this is easy to achieve, but I haven't been able to find anything similar in Visual Studio. Any tips would be much appreciated!
You can set a DocumentSaved handler with Visual Commander and run a tool. See the "2. Run Cppcheck on the saved file and show results in the Output window" extension sample.

Run powershell script at startup in visual studio

I have a powershell file (script.ps1) that is in some of my visual studio solutions. The script contains utility functions for the project.
At the moment, I just open the nugget package manager and copy and paste the content of the script and it runs fine. I can run the functions correctly from the nugget package manager. But this has to be done, each time I open the solution.
Is there a way to get this handle automatically each time I open the solutions?
Rather than copy pasting the entire thing, you can dot source the file
. ".\script.ps1"