I've got some .py and etc. file with code.
How to open it in powershell as text? I mean using invoke-item allows to open .txt in notepad but code.py will be executed using python.
So how to open it using powershell but in notepad at least(in notepad++ preferably)
Invoke-Item will open the application that has the file association for that file extension.
You could try Start-Process. I assume .py files will behave the same as .cs files but
Invoke-Item a.cs opens visual studio
Start-Process notepad a.cs opens notepad
But then again
notepad a.cs opens notepad as well.
If you're really keen to use Invoke-Item it appears its possible to update file associations using PowerShell - change-file-asociations-via-powershell
As already said just use:
notepad yourcode.py
As for notepad++, perhaps the best ways to do it are stated here:
How to execute a PowerShell script from Notepad++
Related
I usually use the shortcut described here: How do I start PowerShell from Windows Explorer? to open a PS session in a specific folder. Just using powershell to open the sessions
However is no longer working, every time I write powershell on the address bar and hit enter it take me to the folder: C:\Users\MyUser\Documents\PowerShell (I'm in a Windows 10 laptop)
It seems to be related only to this shortcut as I have tried a few other things and they work. List of things I have tried/checked already below:
powershell -noprofile it work opening a PS session as expected
No, my $Profile file does not have anything to set the location of the PS Session.
powershell.exe works as expected
powershell_ise works as expected
going to File --> Open Windows Powershell works as expected
Checked my environment variables and nothing strange there either
It seems to be related to the fact that I installed PS core 6 recently. This installation introduced the folder C:\Users\MyUser\Documents\PowerShell (it's a new folder vs the ones that existed with Windows Powershell) and that's why the windows explorer now opens a folder instead of the command line.
I suppose I will need to get used to powershell.exe instead of powershell from now on.
I have 10 applications that I constantly work on. At times I need to open them all up separately to run bash commands on them. Is there a way I can create a windows shortcut for each folder, then I select all 10 shortcuts and click enter to initiate 10 different VSCode applications each opens up with their respective folder I set to?
(Windows 10) To open VS Code in desired directory using shortcut:
Create shortcut to Visual Code Studio app,
Right click on the shortcut and select Properties,
In Target field append your directory path (remember to use quotes " " if there are spaces in the path).
ctr + K + O
open a folder vs code most common shortcut key available all platforms same
https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf
I use a batch file like in Sean's solution. You can automatically close the terminal after launch if you use the start command rather than "code ."
Here's an example:
#echo off
cd "C:\path\to\your\project\folder\"
start "" "C:\Program Files\Microsoft VS Code\Code.exe" .
exit
Note: if you don's like how the batch file looks, you can make a shortcut to the batch file and change the shortcut's icon to the VS Code icon.
In a similar situation, I use a batch file to launch my most used vscode windows. I am not yet smart enough to make the cmd windows disappear after they open vscode, but maybe someday. In each batch file, use the following changing the directory for each project.
#ECHO OFF
cd C:\directory\where\your\project\is
code .
exit
I have "terminal.integrated.shell.windows": "C:\\Program Files (x86)\\PowerShell\\6\\pwsh.exe" set in my settings.json file, and when I open VS code without any files open the terminal is set to pwsh, but when I open a PowerShell script, there is suddenly a second terminal (PowerShell Integrated Console) and running the debugger results in PowerShell 5.1 being used instead of 6 (Core).
What do I need to do to get PowerShell version 6 used whenever I open a .ps1 document? Running it from the command line works, but is a pain.
The PowerShell Integrated Console is what the PowerShell extension uses to process .ps1 files and is controlled by a different setting (powershell.powerShellExePath).
You can change this setting easily by opening a .ps1 file, then clicking on the "5.1", "6.0", etc. icon in the bottom right of the status bar. This will open the PowerShell Session Menu where you can select which version of PowerShell you want the extension to use (out of the versions you have installed).
Your choice will then be persisted in your user settings under powershell.powerShellExePath.
I am looking for a way to open a file in the windows explorer.
The file directory is stored in a QR Code, after decoding, the path gets copied to the clipboard. From there it needs to be opened in the windows explorer because the QR Decoder doesn't automatically recognize the code as a file path.
Is there a way to process a file path in Powershell and open it in the windows explorer?
If you have a recent version of Powershell then you can just do this:
explorer (Get-Clipboard)
You can open a folder in Windows Explorer via PowerShell like this:
[System.Diagnostics.Process]::Start(<FolderPath>)
Or this:
Start-Process -FilePath <FolderPath>
This also works for other items, such as URLs, which will open in your default browser.
In Visual Studio Code, I would like to open a PowerShell window (outside of VSC) with the shortcut Ctrl+Shift+C.
By default, this shortcut will open a cmd.exe, so I would like to replace it.
You can set the terminal.external.windowsExec setting in settings.json. See this to find PowerShell's executable path if yours isn't the default one.
"terminal.external.windowsExec": "C:\\WINDOWS\\system32\\WindowsPowerShell\\1.0\\powershell.exe"