I'm looking for a way to replicate the $psISE functionality in VSCode, at least as far as discovering the filename of the open, active file in the editor.
As background:
I'm trying to migrate into using VSCode for powershell editing instead of the ISE since VSCode is the future. We're having issues with migrating some workflows (specifically signing scripts). In the ISE, I have created a function that uses the $psise.currentfile.fullpath
so that we can easily sign the file that's open in the ISE. I'd like to recreate this for vscode, but I'm not finding any way to determine what the open file is. We tend to run this interactively (i.e. we're testing in the ISE, get it to where we want to test on another box, and sign it by just typing Set-CoSAuthenticodeSignature
, which is a custom function that wraps set-authenticodesignature
but has defaults set and automatically finds the file, if we don't specify), so we don't want to have to type the path name all the time, especially since we don't have to now.
Thanks!
Visual Studio Code Extension for Tizen Web supports WYSIWYG Design Editor features such as Preview, JavaScript Assistant, Structure View, New Page, HTML Assistant, Undo, and Redo.
Once it is saved as a PS1, VS Code will identify the file as a PowerShell script. From there, you can execute the PowerShell script by press F5 . You can also click the Run button on the top right of the editor. To run a select, you can press F8 or right click on the selection and click the Run Selection option.
Brief: VSCodium is a clone of Microsoft's popular Visual Studio Code editor. It's identical to VS Code with the single biggest difference that unlike VS Code, VSCodium doesn't track your usage data. Microsoft's Visual Studio Code is an excellent editor not only for web developers but also for other programmers.
VS Code Auto Format On SaveOpen Visual Studio Code editor. Click the “Settings” gear icon in the bottom-left corner. Search “Formatter” and click the “Editor: Default Formatter” option. From the drop-down menu, select whichever code formatter you want to use.
$ScriptPath=''
if($ScriptPath -eq '' -and $MyInvocation.MyCommand.CommandType -eq 'ExternalScript'){$ScriptPath = (Split-Path -Path $MyInvocation.MyCommand.Source -Parent)} # Running from File
if($ScriptPath -eq '' -and (Test-Path variable:psISE)) { $ScriptPath = (Split-Path -Path $psISE.CurrentFile.FullPath -Parent)} # Running from ISE
if($ScriptPath -eq '' -and (Test-Path variable:psEditor)) { $ScriptPath = (Split-Path -Path $psEditor.GetEditorContext().CurrentFile.Path -Parent)} # Running from Visual Studio Code
I think it's not implemented yet (the $psise). You can file an issue on the vscode-powershell Project for VSCode. A similar one has already been filed.
At least you might use something like
$context = [Microsoft.Powershell.EditorServices.Extensions.EditorContext]$psEditor.GetEditorContext()
Then you can access the current file...
$context.CurrentFile.
See also this video for an introduction...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With