|
@@ -14,7 +14,7 @@ Function Open-Solution {
|
|
[CmdletBinding()]
|
|
[CmdletBinding()]
|
|
param(
|
|
param(
|
|
[Parameter(Mandatory=$false, HelpMessage="The path to the solution file to open.")]
|
|
[Parameter(Mandatory=$false, HelpMessage="The path to the solution file to open.")]
|
|
- [Uri]$SolutionFilePath
|
|
|
|
|
|
+ [Uri]$SolutionFilePath = (Resolve-Path "../Terminal.sln")
|
|
)
|
|
)
|
|
|
|
|
|
if(!$IsWindows) {
|
|
if(!$IsWindows) {
|
|
@@ -44,6 +44,52 @@ Function Close-Solution {
|
|
Remove-Variable vsProcesses
|
|
Remove-Variable vsProcesses
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+<#
|
|
|
|
+ .SYNOPSIS
|
|
|
|
+ Sets up a standard environment for other Terminal.Gui.PowerShell scripts and modules.
|
|
|
|
+ .DESCRIPTION
|
|
|
|
+ Configures environment variables and global variables for other Terminal.Gui.PowerShell scripts to use.
|
|
|
|
+ Also modifies the prompt to indicate the session has been altered.
|
|
|
|
+ Reset changes by exiting the session or by calling Reset-PowerShellEnvironment or ./ResetEnvironment.ps1.
|
|
|
|
+ .PARAMETER Debug
|
|
|
|
+ Minimally supported for Write-Debug calls in this function only.
|
|
|
|
+ .NOTES
|
|
|
|
+ Mostly does not respect common parameters like WhatIf, Confirm, etc.
|
|
|
|
+ This is just meant to be called by other scripts.
|
|
|
|
+ Calling this manually is not supported.
|
|
|
|
+#>
|
|
|
|
+Function Set-PowerShellEnvironment {
|
|
|
|
+ [CmdletBinding()]
|
|
|
|
+ param()
|
|
|
|
+
|
|
|
|
+ # Set a custom prompt to indicate we're in our modified environment.
|
|
|
|
+ # Save the normal one first, though.
|
|
|
|
+ # And save it as ReadOnly and without the -Force parameter, so this will be skipped if run more than once in the same session without a reset.
|
|
|
|
+ New-Variable -Name NormalPrompt -Option ReadOnly -Scope Global -Value (Get-Item Function:prompt).ScriptBlock -ErrorAction SilentlyContinue
|
|
|
|
+ Set-Item Function:prompt { "TGPS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) "; }
|
|
|
|
+
|
|
|
|
+ # Save existing PSModulePath for optional reset later.
|
|
|
|
+ # If it is already saved, do not overwrite, but continue anyway.
|
|
|
|
+ New-Variable -Name OriginalPSModulePath -Visibility Public -Option ReadOnly -Scope Global -Value ($Env:PSModulePath) -ErrorAction SilentlyContinue
|
|
|
|
+ Write-Debug -Message "`$OriginalPSModulePath is $OriginalPSModulePath" -Debug:$DebugPreference
|
|
|
|
+
|
|
|
|
+ # Get platform-specific path variable entry separator. Continue if it's already set.
|
|
|
|
+ New-Variable -Name PathVarSeparator -Visibility Public -Option ReadOnly -Scope Global -Value ";" -Description 'Separator character used in environment variables such as $Env:PSModulePath' -ErrorAction SilentlyContinue
|
|
|
|
+
|
|
|
|
+ if(!$IsWindows) {
|
|
|
|
+ $PathVarSeparator = ':'
|
|
|
|
+ }
|
|
|
|
+ Write-Debug -Message "`$PathVarSeparator is $PathVarSeparator" -Debug:$DebugPreference
|
|
|
|
+
|
|
|
|
+ # If Env:PSModulePath already has the current path, don't append it again.
|
|
|
|
+ if($Env:PSModulePath -notlike "*$((Resolve-Path .).Path)*") {
|
|
|
|
+ Write-Debug -Message "Appending $((Resolve-Path .).Path) to `$Env:PSModulePath" -Debug:$DebugPreference
|
|
|
|
+ $env:PSModulePath = Join-String -Separator $PathVarSeparator -InputObject @( $env:PSModulePath, (Resolve-Path .).Path )
|
|
|
|
+ }
|
|
|
|
+ Write-Debug -Message "`$Env:PSModulePath is $Env:PSModulePath" -Debug:$DebugPreference
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
<#
|
|
<#
|
|
.SYNOPSIS
|
|
.SYNOPSIS
|
|
Resets changes made by ConfigureEnvironment.pst to the current PowerShell environment.
|
|
Resets changes made by ConfigureEnvironment.pst to the current PowerShell environment.
|
|
@@ -65,8 +111,9 @@ Function Close-Solution {
|
|
To exit the current session. Same as simply using the Exit command.
|
|
To exit the current session. Same as simply using the Exit command.
|
|
#>
|
|
#>
|
|
Function Reset-PowerShellEnvironment {
|
|
Function Reset-PowerShellEnvironment {
|
|
|
|
+ [CmdletBinding(DefaultParameterSetName="Basic")]
|
|
param(
|
|
param(
|
|
- [Parameter(Mandatory = $false)]
|
|
|
|
|
|
+ [Parameter(Mandatory=$false, ParameterSetName="Basic")]
|
|
[switch]$Exit
|
|
[switch]$Exit
|
|
)
|
|
)
|
|
|
|
|
|
@@ -76,67 +123,21 @@ Function Reset-PowerShellEnvironment {
|
|
|
|
|
|
if(Get-Variable -Name NormalPrompt -Scope Global -ErrorAction SilentlyContinue){
|
|
if(Get-Variable -Name NormalPrompt -Scope Global -ErrorAction SilentlyContinue){
|
|
Set-Item Function:prompt $NormalPrompt
|
|
Set-Item Function:prompt $NormalPrompt
|
|
- Remove-Variable -Name NormalPrompt -Scope Global -Force
|
|
|
|
|
|
+ Remove-Variable -Name NormalPrompt -Scope Global -Force -ErrorAction SilentlyContinue
|
|
}
|
|
}
|
|
|
|
|
|
if(Get-Variable -Name OriginalPSModulePath -Scope Global -ErrorAction SilentlyContinue){
|
|
if(Get-Variable -Name OriginalPSModulePath -Scope Global -ErrorAction SilentlyContinue){
|
|
$Env:PSModulePath = $OriginalPSModulePath
|
|
$Env:PSModulePath = $OriginalPSModulePath
|
|
- Remove-Variable -Name OriginalPSModulePath -Scope Global -Force
|
|
|
|
|
|
+ Remove-Variable -Name OriginalPSModulePath -Scope Global -Force -ErrorAction SilentlyContinue
|
|
}
|
|
}
|
|
|
|
|
|
Remove-Variable -Name PathVarSeparator -Scope Global -Force -ErrorAction SilentlyContinue
|
|
Remove-Variable -Name PathVarSeparator -Scope Global -Force -ErrorAction SilentlyContinue
|
|
}
|
|
}
|
|
|
|
|
|
-<#
|
|
|
|
- .SYNOPSIS
|
|
|
|
- Sets up a standard environment for other Terminal.Gui.PowerShell scripts and modules.
|
|
|
|
- .DESCRIPTION
|
|
|
|
- Configures environment variables and global variables for other Terminal.Gui.PowerShell scripts to use.
|
|
|
|
- Also modifies the prompt to indicate the session has been altered.
|
|
|
|
- Reset changes by exiting the session or by calling Reset-PowerShellEnvironment or ./ResetEnvironment.ps1.
|
|
|
|
-#>
|
|
|
|
-
|
|
|
|
-<#
|
|
|
|
- .SYNOPSIS
|
|
|
|
- Sets up a standard environment for other Terminal.Gui.PowerShell scripts and modules.
|
|
|
|
- .DESCRIPTION
|
|
|
|
- Configures environment variables and global variables for other Terminal.Gui.PowerShell scripts to use.
|
|
|
|
- Also modifies the prompt to indicate the session has been altered.
|
|
|
|
- Reset changes by exiting the session or by calling Reset-PowerShellEnvironment or ./ResetEnvironment.ps1.
|
|
|
|
-#>
|
|
|
|
-Function Set-PowerShellEnvironment {
|
|
|
|
- # Set a custom prompt to indicate we're in our modified environment.
|
|
|
|
- # Save the normal one first, though.
|
|
|
|
- New-Variable -Name NormalPrompt -Option ReadOnly -Scope Global -Value (Get-Item Function:prompt).ScriptBlock -ErrorAction SilentlyContinue
|
|
|
|
- Set-Item Function:prompt { "TGPS $($executionContext.SessionState.Path.CurrentLocation)$('>' * ($nestedPromptLevel + 1)) "; }
|
|
|
|
-
|
|
|
|
- # Save existing PSModulePath for optional reset later.
|
|
|
|
- # If it is already saved, do not overwrite, but continue anyway.
|
|
|
|
- New-Variable -Name OriginalPSModulePath -Visibility Public -Option ReadOnly -Scope Global -Value ($Env:PSModulePath) -ErrorAction SilentlyContinue
|
|
|
|
- Write-Debug -Message "`$OriginalPSModulePath is $OriginalPSModulePath"
|
|
|
|
-
|
|
|
|
- # Get platform-specific path variable entry separator. Continue if it's already set.
|
|
|
|
- New-Variable -Name PathVarSeparator -Visibility Public -Option ReadOnly,Constant -Scope Global -Value ";" -Description 'Separator character used in environment variables such as $Env:PSModulePath' -ErrorAction SilentlyContinue
|
|
|
|
-
|
|
|
|
- if(!$IsWindows) {
|
|
|
|
- $PathVarSeparator = ':'
|
|
|
|
- }
|
|
|
|
- Write-Debug -Message "`$PathVarSeparator is $PathVarSeparator"
|
|
|
|
-
|
|
|
|
- # Now make it constant.
|
|
|
|
- Set-Variable PathVarSeparator -Option Constant -ErrorAction SilentlyContinue
|
|
|
|
-
|
|
|
|
- # If Env:PSModulePath already has the current path, don't append it again.
|
|
|
|
- if($Env:PSModulePath -notlike "*$((Resolve-Path .).Path)*") {
|
|
|
|
- Write-Debug -Message "Appending $((Resolve-Path .).Path) to `$Env:PSModulePath"
|
|
|
|
- $env:PSModulePath = Join-String -Separator $PathVarSeparator -InputObject @( $env:PSModulePath, (Resolve-Path .).Path )
|
|
|
|
- }
|
|
|
|
- Write-Debug -Message "`$Env:PSModulePath is $Env:PSModulePath"
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
# This ensures the environment is reset when unloading the module.
|
|
# This ensures the environment is reset when unloading the module.
|
|
# Without this, function:prompt will be undefined.
|
|
# Without this, function:prompt will be undefined.
|
|
$MyInvocation.MyCommand.ScriptBlock.Module.OnRemove = {
|
|
$MyInvocation.MyCommand.ScriptBlock.Module.OnRemove = {
|
|
Reset-PowerShellEnvironment
|
|
Reset-PowerShellEnvironment
|
|
- Pop-Location
|
|
|
|
-}
|
|
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+Set-PowerShellEnvironment
|