Quick Edits Using VS Code

I’ve been working in Visual Studio pretty heavily in the last two weeks, but every once in a while I need to make quick edits to my .gitignore file, which isn’t in my project directory.

I usually open up a small text editor right from PowerShell and now that VS Code is out I thought ‘why not use that?’

Here’s how you can easily open files using code from PowerShell in three steps:

1.Find the path to VS Code
2. Edit your PowerShell profile
3. Open Files!

1. Find the VS Code Path

First thing we need to do is find where VS Code is in our directory.

If you have Code pinned to your start menu or on your desktop simply right click the icon and ‘select open file location’.

File explorer should now open to the location of the .exe.
Right click the Code.exe file and select ‘properties’.

If you selected a Shortcut Icon you should see a screen like this:

vscodeshortcutpath

If you navigated to the actual location in directory of VS Code it should look like this:

vscodelocationpath

Now right click and copy the path.

In my case: C:\Users\tireilly\AppData\Local\Code\app-0.1.0

2. Edit our PowerShell profile

To edit our profile we need to find the Microsoft.PowerShell_profile.ps1 file.

My file is located here:

profilelocationpowershell

I open the file in notepad to make my edits:

notepadpowershellprofile

Now that we have our profile open we’ll create an alias for labeled code followed by the path to our .exe
eg: Set-Alias code ‘C:\Users\user\AppData\Local\Code\app-0.1.0\Code.exe

noticed how I added the Code.exe to the path so the program will launch!

Here’s a photo of my current PowerShell profile for reference:

powershellprofile

Now we can save and close this file and open a new PowerShell window!

3. Edit some files!

Let’s edit our PowerShell profile with Code this time!

symmetryisgood

Something oddly satisfying about getting exactly what you want with words.

codeeditorpowershellprofile

And there we go. The brand new Code editor at your fingertips whenever you need it!

Let me know if you have any comment or questions!

Amazing Dude
Professor Chang Yun is an excellent man with an amazing imagine cup record. His mentorship has led teams to US finals for 8 years straight. With 6 teams making it into the World Finals.

Running Multiple Python Versions on Windows

So, you are learning to develop with Python and you keep hopping back and forth from Python 2.x and Python 3.x and possibly versions in between.

Beside running everything in a virtual environment, its sometimes nice to just get to the different REPLs to test tiny pieces of code.

This can be managed easily in powershell using powershell profile.
This link helped me learn about what it is and how to set it up.

But basically, you establish shortcuts by customizing a profile page with the things you need to access quickly.

Currently in my Profile I have a shortcut for starting Python27, Python34, and Sublime.

I’ll show you how I set it up.
First we’ll edit our Profile, then we’ll change the execution policy to allow this file to edit PowerShell.

Open powershell!

1. Type the following command and press ENTER:

Test-Path $profile

2. If False you need to create a profile, if true go to step 3:

New-item -type file -force $profile

3. Go to you PowerShell Directory. Step 2 will show the path to the location. For me its Users\tireilly\Documents\WindowsPowerShell.

4. Open your profile:

Notepad .\Microsoft.PowerShell_profile.ps1

5. Now in Notepad you can add your aliases.

This is what I have:

Set-Alias subl 'C:\Program Files (x86)\Sublime Text 2\sublime_text.exe'
Set-Alias python34 'C:\Python34\python.exe'
Set-Alias python27 'C:\Python27\python.exe'

Make sure you have the proper path to your existence of python. I have mine in my Root directory.

Now to activate this you need to set the execution policy to allow this to be activate each time you open powershell.

To do this follow these steps:

1. Determine your current execution policy.

Get-ExecutionPolicy

This is just to double check you are restricted either way set it again to be sure.

2. Set Execution policy for yourself.

Set-ExecutionPolicy -Scope CurrentUser

3. You’ll be prompted with “ExecutionPolicy: ”
Set it as unrestricted
It should look like this:
ExecutionPolicy: Unrestricted"
Press enter.

4. Comfirm by entering ‘Y’ and pressing enter again.

Now Restart Power shell and try typing in your alias!
Does Python Start?

If not, I’m happy to help if you have any questions.

This Photo is from 2010... Just saying
This Photo is from 2010…