From b88086747b674a395cf631d167f8d04099814c7d Mon Sep 17 00:00:00 2001 From: corbob Date: Thu, 17 Oct 2019 06:14:31 -0700 Subject: [PATCH 1/2] Add WithInsiders switch. Fixes #22 --- PSProfile/Public/Power Tools/Open-Code.ps1 | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/PSProfile/Public/Power Tools/Open-Code.ps1 b/PSProfile/Public/Power Tools/Open-Code.ps1 index 0620be7..61cde1a 100644 --- a/PSProfile/Public/Power Tools/Open-Code.ps1 +++ b/PSProfile/Public/Power Tools/Open-Code.ps1 @@ -24,6 +24,9 @@ function Open-Code { .PARAMETER Wait If $true, waits for the file to be closed in Code before returning to the prompt. If $false, opens the file using a background job to allow immediately returning to the prompt. Defaults to $false. + .PARAMETER WithInsiders + If $true, looks for VS Code Insiders to load. If $true and code-insiders cannot be found, opens the file using VS Code stable. If $false, opens the file using VS Code stable. Defaults to $false. + .PARAMETER ArgumentList Any additional arguments to be passed directly to the Code CLI command, e.g. `Open-Code --list-extensions` or `code --list-extensions` will still work the same as expected. @@ -61,6 +64,10 @@ function Open-Code { [Alias('w')] [Switch] $Wait, + [Alias('wi')] + [Alias('insiders')] + [Switch] + $WithInsiders, [parameter(ValueFromRemainingArguments)] [String[]] $ArgumentList @@ -111,7 +118,12 @@ function Open-Code { } } Process { - $code = (Get-Command code -All | Where-Object { $_.CommandType -notin @('Function','Alias') })[0].Source + if($WithInsiders) { + $code = (Get-Command code-insiders -All | Where-Object { $_.CommandType -notin @('Function','Alias') })[0].Source + } + if($null -eq $code){ + $code = (Get-Command code -All | Where-Object { $_.CommandType -notin @('Function','Alias') })[0].Source + } if ($PSCmdlet.ParameterSetName -eq 'InputObject') { $collection.Add($InputObject) if ($PSBoundParameters.ContainsKey('Path')) { From 431d36b7607abf2e9a27bdc9b132757124b71142 Mon Sep 17 00:00:00 2001 From: corbob Date: Thu, 17 Oct 2019 06:21:16 -0700 Subject: [PATCH 2/2] Update code detection logic. Now if -WithInsiders is specified, looks for code-insiders first. Also looks for insiders after looking for code by default so if you don't have stable installed, you can still use the function --- PSProfile/Public/Power Tools/Open-Code.ps1 | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/PSProfile/Public/Power Tools/Open-Code.ps1 b/PSProfile/Public/Power Tools/Open-Code.ps1 index 61cde1a..bc4fdbe 100644 --- a/PSProfile/Public/Power Tools/Open-Code.ps1 +++ b/PSProfile/Public/Power Tools/Open-Code.ps1 @@ -118,12 +118,11 @@ function Open-Code { } } Process { + $codeCommand = @('code','code-insiders') if($WithInsiders) { - $code = (Get-Command code-insiders -All | Where-Object { $_.CommandType -notin @('Function','Alias') })[0].Source - } - if($null -eq $code){ - $code = (Get-Command code -All | Where-Object { $_.CommandType -notin @('Function','Alias') })[0].Source + $codeCommand = @('code-insiders','code') } + $code = (Get-Command $codeCommand -All | Where-Object { $_.CommandType -notin @('Function','Alias') })[0].Source if ($PSCmdlet.ParameterSetName -eq 'InputObject') { $collection.Add($InputObject) if ($PSBoundParameters.ContainsKey('Path')) {