edpiza
Last Updated: April 30, 2016
·
1.658K
· khaos
676489

Set PowerShell edit command for quick file editing

This one is dead simple, but I've tired of finding out the correct way of doing it in the Internet every time I need to configure PowerShell on a new installation.

It's known that Windows lacks default file editing tool accessible from the command line (notepad.exe does not count as one). So, let's create a macro that will bring up you favorite editor (mine is SiblimeText) on edit command for example. Really simple, but to make sure that this alias will be persistent across your shells, the file profile.ps1 should be created having the following path:
$Home\Documents\WindowsPowerShell\profile.ps1

It will be executed every time new shell is opened. Inside the following code should be placed to create an Edit macro:

New-Alias Edit "${env:ProgramFiles}\Sublime Text 3\sublime_text.exe"

The actual path can vary if you're using some editor other than Sublime. Now, text files can be created and edited from the console with edit command: edit somefile.txt.

Say Thanks
Respond