-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
173 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
PSProfile/Public/Configuration/Add-PSProfileConfigurationPath.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
function Add-PSProfileConfigurationPath { | ||
<# | ||
.SYNOPSIS | ||
Adds a ConfigurationPath to your PSProfile to import during PSProfile load. | ||
.DESCRIPTION | ||
Adds a ConfigurationPath to your PSProfile to import during PSProfile load. Useful for synced configurations. | ||
.PARAMETER Path | ||
The path of the script to add to your $PSProfile.ConfigurationPaths. | ||
.PARAMETER Save | ||
If $true, saves the updated PSProfile after updating. | ||
.EXAMPLE | ||
Add-PSProfileConfigurationPath -Path ~\SyncConfiguration.psd1 -Save | ||
Adds the configuration 'SyncConfiguration.ps1' to $PSProfile.ConfigurationPaths and saves the configuration after updating. | ||
.EXAMPLE | ||
Get-ChildItem .\PSProfileConfigurations -Recurse -File | Add-PSProfileConfigurationPath -Verbose | ||
Adds all psd1 files under the PSProfileConfigurations folder to $PSProfile.ConfigurationPaths but does not save to allow inspection. Call Save-PSProfile after to save the results if satisfied. | ||
#> | ||
[CmdletBinding()] | ||
Param ( | ||
[Parameter(Mandatory,Position = 0,ValueFromPipeline,ValueFromPipelineByPropertyName)] | ||
[Alias('FullName')] | ||
[String[]] | ||
$Path, | ||
[Parameter()] | ||
[Switch] | ||
$Save | ||
) | ||
Process { | ||
foreach ($p in $Path) { | ||
if ($p -match '\.psd1$') { | ||
$fP = (Resolve-Path $p).Path | ||
if ($Global:PSProfile.ConfigurationPaths -notcontains $fP) { | ||
Write-Verbose "Adding ConfigurationPath to PSProfile: $fP" | ||
$Global:PSProfile.ConfigurationPaths += $fP | ||
} | ||
else { | ||
Write-Verbose "ConfigurationPath already in PSProfile: $fP" | ||
} | ||
} | ||
else { | ||
Write-Verbose "Skipping non-psd1 file: $fP" | ||
} | ||
} | ||
if ($Save) { | ||
Save-PSProfile | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
PSProfile/Public/Configuration/Get-PSProfileConfigurationPath.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
function Get-PSProfileConfigurationPath { | ||
<# | ||
.SYNOPSIS | ||
Gets a configuration path from $PSProfile.ConfigurationPaths. | ||
.DESCRIPTION | ||
Gets a configuration path from $PSProfile.ConfigurationPaths. | ||
.PARAMETER Path | ||
The configuration path to get from $PSProfile.ConfigurationPaths. | ||
.EXAMPLE | ||
Get-PSProfileConfigurationPath -Path E:\Git\MyPSProfileConfig.psd1 | ||
Gets the path 'E:\Git\MyPSProfileConfig.psd1' from $PSProfile.ConfigurationPaths | ||
.EXAMPLE | ||
Get-PSProfileConfigurationPath | ||
Gets the list of configuration paths from $PSProfile.ConfigurationPaths | ||
#> | ||
[CmdletBinding()] | ||
Param ( | ||
[Parameter(Position = 0,ValueFromPipeline)] | ||
[String[]] | ||
$Path | ||
) | ||
Process { | ||
if ($PSBoundParameters.ContainsKey('Path')) { | ||
Write-Verbose "Getting configuration path '$Path' from `$PSProfile.ConfigurationPaths" | ||
$Global:PSProfile.ConfigurationPaths | Where-Object {$_ -match "($(($Path | ForEach-Object {[regex]::Escape($_)}) -join '|'))"} | ||
} | ||
else { | ||
Write-Verbose "Getting all configuration paths from `$PSProfile.ConfigurationPaths" | ||
$Global:PSProfile.ConfigurationPaths | ||
} | ||
} | ||
} | ||
|
||
Register-ArgumentCompleter -CommandName Get-PSProfileConfigurationPath -ParameterName Path -ScriptBlock { | ||
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) | ||
$Global:PSProfile.ConfigurationPaths | Where-Object {$_ -like "$wordToComplete*"} | ForEach-Object { | ||
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
PSProfile/Public/Configuration/Remove-PSProfileConfigurationPath.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
function Remove-PSProfileConfigurationPath { | ||
<# | ||
.SYNOPSIS | ||
Removes a configuration path from $PSProfile.ConfigurationPaths. | ||
.DESCRIPTION | ||
Removes a configuration path from $PSProfile.ConfigurationPaths. | ||
.PARAMETER Path | ||
The path to remove from $PSProfile.ConfigurationPaths. | ||
.PARAMETER Save | ||
If $true, saves the updated PSProfile after updating. | ||
.EXAMPLE | ||
Remove-PSProfileConfigurationPath -Name ~\PSProfile\MyConfig.psd1 -Save | ||
Removes the path '~\PSProfile\MyConfig.psd1' from $PSProfile.ConfigurationPaths then saves the updated configuration. | ||
#> | ||
[CmdletBinding(SupportsShouldProcess,ConfirmImpact = "High")] | ||
Param ( | ||
[Parameter(Mandatory,Position = 0,ValueFromPipeline)] | ||
[String] | ||
$Path, | ||
[Parameter()] | ||
[Switch] | ||
$Save | ||
) | ||
Process { | ||
if ($PSCmdlet.ShouldProcess("Removing '$Path' from `$PSProfile.ConfigurationPaths")) { | ||
Write-Verbose "Removing '$Path' from `$PSProfile.ConfigurationPaths" | ||
$Global:PSProfile.ConfigurationPaths = $Global:PSProfile.ConfigurationPaths | Where-Object {$_ -notin @($Path,(Resolve-Path $Path).Path)} | ||
if ($Save) { | ||
Save-PSProfile | ||
} | ||
} | ||
} | ||
} | ||
|
||
Register-ArgumentCompleter -CommandName Remove-PSProfileConfigurationPath -ParameterName Path -ScriptBlock { | ||
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter) | ||
$Global:PSProfile.ConfigurationPaths | Where-Object {$_ -like "$wordToComplete*"} | ForEach-Object { | ||
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters