feat(pwsh): disable module support by default

This commit is contained in:
Jan De Dobbeleer 2021-05-21 08:50:41 +02:00 committed by Jan De Dobbeleer
parent 894b84fa85
commit c3b6f31d09
4 changed files with 29 additions and 11 deletions

View file

@ -8,6 +8,11 @@ sidebar_label: Azure
Display the currently active Azure subscription information.
:::info
PowerShell offers support for the `Az.Accounts` module, but it is disabled by default.
To enable this, set `$env:AZ_ENABLED = $true` in your `$PROFILE`.
:::
## Sample Configuration
```json

View file

@ -14,6 +14,11 @@ Local changes can also shown by default using the following syntax for both the
- `-` deleted
- `?` untracked
:::info
PowerShell offers support for the `posh-git` module for autocompletion, but it is disabled by default.
To enable this, set `$env:POSH_GIT_ENABLED = $true` in your `$PROFILE`.
:::
## Sample Configuration
```json

View file

@ -10,6 +10,7 @@ Display the [posh-git][posh-git] prompt.
:::info
This segment only works within Powershell and requires the posh-git module to be installed and imported.
To enable the `posh-git` module, set `$env:POSH_GIT_ENABLED = $true` in your `$PROFILE`.
:::
## Sample Configuration

View file

@ -4,6 +4,23 @@
$env:POWERLINE_COMMAND = "oh-my-posh"
$env:CONDA_PROMPT_MODIFIER = $false
# specific module support (disabled by default)
function Set-DefaultEnvValue {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]
$Name
)
$value = [System.Environment]::GetEnvironmentVariable($Name)
if ($value -eq $null) {
[System.Environment]::SetEnvironmentVariable($Name, $false)
}
}
Set-DefaultEnvValue("AZ_ENABLED")
Set-DefaultEnvValue("POSH_GIT_ENABLED")
$global:PoshSettings = New-Object -TypeName PSObject -Property @{
Theme = "";
}
@ -19,22 +36,12 @@ if (Test-Path $config) {
function global:Set-PoshContext {}
function global:Initialize-ModuleSupport {
if (Get-Module -Name "posh-git") {
if ($env:POSH_GIT_ENABLED -eq $true -and (Get-Module -Name "posh-git")) {
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSProvideCommentHelp', '', Justification = 'Variable used later(not in this scope)')]
$global:GitStatus = Get-GitStatus
$env:POSH_GIT_STATUS = Write-GitStatus -Status $global:GitStatus
}
if ($null -eq $env:AZ_ENABLED) {
if (Get-Module -ListAvailable -Name "Az.Accounts") {
$env:AZ_ENABLED = $true
}
else {
$env:AZ_ENABLED = $false
}
}
$env:AZ_SUBSCRIPTION_NAME = $null
$env:AZ_SUBSCRIPTION_ID = $null