Skip to content

Commit 1dca0bb

Browse files
committed
!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
1 parent 21487ea commit 1dca0bb

File tree

4 files changed

+66
-20
lines changed

4 files changed

+66
-20
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
* [PSProfile - ChangeLog](#psprofile---changelog)
2+
* [0.6.1 - 2019-11-04](#061---2019-11-04)
23
* [0.6.0 - 2019-11-02](#060---2019-11-02)
34
* [0.5.0 - 2019-10-08](#050---2019-10-08)
45
* [0.4.1 - 2019-10-08](#041---2019-10-08)
@@ -20,6 +21,11 @@
2021

2122
# PSProfile - ChangeLog
2223

24+
## 0.6.1 - 2019-11-04
25+
26+
* Miscellaneous
27+
* Fixed: Errors thrown on functions `Open-Code`, `Edit-PSProfileInitScript`, & `Edit-PSProfilePrompt` when `code-insiders` is not installed
28+
2329
## 0.6.0 - 2019-11-02
2430

2531
* [Issue #21](https://github.com/scrthq/PSProfile/issues/21) - _Thank you [@corbob](https://github.com/corbob)!_

PSProfile/Public/Init Scripts/Edit-PSProfileInitScript.ps1

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,27 @@ function Edit-PSProfileInitScript {
3434
$Save
3535
)
3636
Process {
37-
$codeCommand = @('code','code-insiders')
38-
if ($WithInsiders) {
39-
$codeCommand = @('code-insiders','code')
37+
$code = $null
38+
$codeCommand = if($WithInsiders) {
39+
@('code-insiders','code')
40+
}
41+
else {
42+
@('code','code-insiders')
43+
}
44+
foreach ($cmd in $codeCommand) {
45+
try {
46+
if ($found = (Get-Command $cmd -All -ErrorAction Stop | Where-Object { $_.CommandType -notin @('Function','Alias') } | Select-Object -First 1 -ExpandProperty Source)) {
47+
$code = $found
48+
break
49+
}
50+
}
51+
catch {
52+
$Global:Error.Remove($Global:Error[0])
53+
}
54+
}
55+
if ($null -eq $code){
56+
throw "Editor not found!"
4057
}
41-
$code = (Get-Command $codeCommand -All | Where-Object { $_.CommandType -notin @('Function','Alias') })[0].Source
4258
foreach ($initScript in $Name) {
4359
if ($Global:PSProfile.InitScripts.Contains($initScript)) {
4460
$in = @{

PSProfile/Public/Power Tools/Open-Code.ps1

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,27 @@ function Open-Code {
118118
}
119119
}
120120
Process {
121-
$codeCommand = @('code','code-insiders')
122-
if($WithInsiders) {
123-
$codeCommand = @('code-insiders','code')
121+
$code = $null
122+
$codeCommand = if($WithInsiders) {
123+
@('code-insiders','code')
124+
}
125+
else {
126+
@('code','code-insiders')
127+
}
128+
foreach ($cmd in $codeCommand) {
129+
try {
130+
if ($found = (Get-Command $cmd -All -ErrorAction Stop | Where-Object { $_.CommandType -notin @('Function','Alias') } | Select-Object -First 1 -ExpandProperty Source)) {
131+
$code = $found
132+
break
133+
}
134+
}
135+
catch {
136+
$Global:Error.Remove($Global:Error[0])
137+
}
138+
}
139+
if ($null -eq $code){
140+
throw "Editor not found!"
124141
}
125-
$code = (Get-Command $codeCommand -All | Where-Object { $_.CommandType -notin @('Function','Alias') })[0].Source
126142
if ($PSCmdlet.ParameterSetName -eq 'InputObject') {
127143
$collection.Add($InputObject)
128144
if ($PSBoundParameters.ContainsKey('Path')) {
@@ -159,14 +175,6 @@ function Open-Code {
159175
[System.IO.Path]::Combine($global:PSProfile.GitPathMap['chef-repo'],'cookbooks',$PSBoundParameters['Cookbook'])
160176
}
161177
}
162-
<# if ($AddToWorkspace) {
163-
Write-Verbose "Running command: code --add $($PSBoundParameters[$PSCmdlet.ParameterSetName]) $ArgumentList"
164-
& $code --add $target $ArgumentList
165-
}
166-
else {
167-
Write-Verbose "Running command: code $($PSBoundParameters[$PSCmdlet.ParameterSetName]) $ArgumentList"
168-
& $code $target $ArgumentList
169-
} #>
170178
$cmd = @()
171179
if ($AddToWorkspace) {
172180
$cmd += '--add'

PSProfile/Public/Prompts/Edit-PSProfilePrompt.ps1

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,27 @@ function Edit-PSProfilePrompt {
2828
$Save
2929
)
3030
Process {
31-
$codeCommand = @('code','code-insiders')
32-
if ($WithInsiders) {
33-
$codeCommand = @('code-insiders','code')
31+
$code = $null
32+
$codeCommand = if($WithInsiders) {
33+
@('code-insiders','code')
34+
}
35+
else {
36+
@('code','code-insiders')
37+
}
38+
foreach ($cmd in $codeCommand) {
39+
try {
40+
if ($found = (Get-Command $cmd -All -ErrorAction Stop | Where-Object { $_.CommandType -notin @('Function','Alias') } | Select-Object -First 1 -ExpandProperty Source)) {
41+
$code = $found
42+
break
43+
}
44+
}
45+
catch {
46+
$Global:Error.Remove($Global:Error[0])
47+
}
48+
}
49+
if ($null -eq $code){
50+
throw "Editor not found!"
3451
}
35-
$code = (Get-Command $codeCommand -All | Where-Object { $_.CommandType -notin @('Function','Alias') })[0].Source
3652
$in = @{
3753
StdIn = Get-PSProfilePrompt -Global
3854
TmpFile = [System.IO.Path]::Combine(([System.IO.Path]::GetTempPath()),"ps-prompt-$(-join ((97..(97+25)|%{[char]$_}) | Get-Random -Count 3)).ps1")

0 commit comments

Comments
 (0)