From 1dca0bbc549f9b9955e5cefd574703e14ab2f015 Mon Sep 17 00:00:00 2001 From: Nate Ferrell Date: Mon, 4 Nov 2019 15:51:57 -0600 Subject: [PATCH] !deploy v0.6.1 ## 0.6.1 - 2019-11-04 * Miscellaneous * Fixed: Errors thrown on functions `Open-Code`, `Edit-PSProfileInitScript`, & `Edit-PSProfilePrompt` when `code-insiders` is not installed --- CHANGELOG.md | 6 ++++ .../Init Scripts/Edit-PSProfileInitScript.ps1 | 24 +++++++++++--- PSProfile/Public/Power Tools/Open-Code.ps1 | 32 ++++++++++++------- .../Public/Prompts/Edit-PSProfilePrompt.ps1 | 24 +++++++++++--- 4 files changed, 66 insertions(+), 20 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 89412f2..495cbd3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ * [PSProfile - ChangeLog](#psprofile---changelog) + * [0.6.1 - 2019-11-04](#061---2019-11-04) * [0.6.0 - 2019-11-02](#060---2019-11-02) * [0.5.0 - 2019-10-08](#050---2019-10-08) * [0.4.1 - 2019-10-08](#041---2019-10-08) @@ -20,6 +21,11 @@ # PSProfile - ChangeLog +## 0.6.1 - 2019-11-04 + +* Miscellaneous + * Fixed: Errors thrown on functions `Open-Code`, `Edit-PSProfileInitScript`, & `Edit-PSProfilePrompt` when `code-insiders` is not installed + ## 0.6.0 - 2019-11-02 * [Issue #21](https://github.com/scrthq/PSProfile/issues/21) - _Thank you [@corbob](https://github.com/corbob)!_ diff --git a/PSProfile/Public/Init Scripts/Edit-PSProfileInitScript.ps1 b/PSProfile/Public/Init Scripts/Edit-PSProfileInitScript.ps1 index 70f27b6..eab8d58 100644 --- a/PSProfile/Public/Init Scripts/Edit-PSProfileInitScript.ps1 +++ b/PSProfile/Public/Init Scripts/Edit-PSProfileInitScript.ps1 @@ -34,11 +34,27 @@ function Edit-PSProfileInitScript { $Save ) Process { - $codeCommand = @('code','code-insiders') - if ($WithInsiders) { - $codeCommand = @('code-insiders','code') + $code = $null + $codeCommand = if($WithInsiders) { + @('code-insiders','code') + } + else { + @('code','code-insiders') + } + foreach ($cmd in $codeCommand) { + try { + if ($found = (Get-Command $cmd -All -ErrorAction Stop | Where-Object { $_.CommandType -notin @('Function','Alias') } | Select-Object -First 1 -ExpandProperty Source)) { + $code = $found + break + } + } + catch { + $Global:Error.Remove($Global:Error[0]) + } + } + if ($null -eq $code){ + throw "Editor not found!" } - $code = (Get-Command $codeCommand -All | Where-Object { $_.CommandType -notin @('Function','Alias') })[0].Source foreach ($initScript in $Name) { if ($Global:PSProfile.InitScripts.Contains($initScript)) { $in = @{ diff --git a/PSProfile/Public/Power Tools/Open-Code.ps1 b/PSProfile/Public/Power Tools/Open-Code.ps1 index bc4fdbe..0e04f57 100644 --- a/PSProfile/Public/Power Tools/Open-Code.ps1 +++ b/PSProfile/Public/Power Tools/Open-Code.ps1 @@ -118,11 +118,27 @@ function Open-Code { } } Process { - $codeCommand = @('code','code-insiders') - if($WithInsiders) { - $codeCommand = @('code-insiders','code') + $code = $null + $codeCommand = if($WithInsiders) { + @('code-insiders','code') + } + else { + @('code','code-insiders') + } + foreach ($cmd in $codeCommand) { + try { + if ($found = (Get-Command $cmd -All -ErrorAction Stop | Where-Object { $_.CommandType -notin @('Function','Alias') } | Select-Object -First 1 -ExpandProperty Source)) { + $code = $found + break + } + } + catch { + $Global:Error.Remove($Global:Error[0]) + } + } + if ($null -eq $code){ + throw "Editor not found!" } - $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')) { @@ -159,14 +175,6 @@ function Open-Code { [System.IO.Path]::Combine($global:PSProfile.GitPathMap['chef-repo'],'cookbooks',$PSBoundParameters['Cookbook']) } } - <# if ($AddToWorkspace) { - Write-Verbose "Running command: code --add $($PSBoundParameters[$PSCmdlet.ParameterSetName]) $ArgumentList" - & $code --add $target $ArgumentList - } - else { - Write-Verbose "Running command: code $($PSBoundParameters[$PSCmdlet.ParameterSetName]) $ArgumentList" - & $code $target $ArgumentList - } #> $cmd = @() if ($AddToWorkspace) { $cmd += '--add' diff --git a/PSProfile/Public/Prompts/Edit-PSProfilePrompt.ps1 b/PSProfile/Public/Prompts/Edit-PSProfilePrompt.ps1 index a3c61fa..4310d64 100644 --- a/PSProfile/Public/Prompts/Edit-PSProfilePrompt.ps1 +++ b/PSProfile/Public/Prompts/Edit-PSProfilePrompt.ps1 @@ -28,11 +28,27 @@ function Edit-PSProfilePrompt { $Save ) Process { - $codeCommand = @('code','code-insiders') - if ($WithInsiders) { - $codeCommand = @('code-insiders','code') + $code = $null + $codeCommand = if($WithInsiders) { + @('code-insiders','code') + } + else { + @('code','code-insiders') + } + foreach ($cmd in $codeCommand) { + try { + if ($found = (Get-Command $cmd -All -ErrorAction Stop | Where-Object { $_.CommandType -notin @('Function','Alias') } | Select-Object -First 1 -ExpandProperty Source)) { + $code = $found + break + } + } + catch { + $Global:Error.Remove($Global:Error[0]) + } + } + if ($null -eq $code){ + throw "Editor not found!" } - $code = (Get-Command $codeCommand -All | Where-Object { $_.CommandType -notin @('Function','Alias') })[0].Source $in = @{ StdIn = Get-PSProfilePrompt -Global TmpFile = [System.IO.Path]::Combine(([System.IO.Path]::GetTempPath()),"ps-prompt-$(-join ((97..(97+25)|%{[char]$_}) | Get-Random -Count 3)).ps1")