Skip to content

Commit

Permalink
!deploy v0.4.0
Browse files Browse the repository at this point in the history
## 0.4.0 - 2019-09-22

* [Issue #18](#18)
  * Added the following functions for Init Script management:
    * `Add-PSProfileInitScript`
    * `Get-PSProfileInitScript`
    * `Remove-PSProfileInitScript`
    * `Enable-PSProfileInitScript`
    * `Disable-PSProfileInitScript`
    * `Edit-PSProfileInitScript`
  * Added contextual help file `about_PSProfile_Init_Scripts`
  * Added Init Scripts section to `Start-PSProfileConfigurationHelper`
  * Updated `PSProfile` class to include Init Script support.
* Miscellaneous
  * Updated `Edit-PSProfilePrompt` when choosing to Save PSProfile to ensure the updated prompt is written back to disk.
  * Updated `invoke.build.ps1` for better contextual verbosity when compiling the module during the build process.
  • Loading branch information
scrthq committed Sep 23, 2019
1 parent 5c6d66c commit 4781379
Show file tree
Hide file tree
Showing 14 changed files with 604 additions and 18 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
* [PSProfile - ChangeLog](#psprofile---changelog)
* [0.4.0 - 2019-09-22](#040---2019-09-22)
* [0.3.0 - 2019-09-07](#030---2019-09-07)
* [0.2.0 - 2019-09-02](#020---2019-09-02)
* [0.1.9 - 2019-08-26](#019---2019-08-26)
Expand All @@ -16,6 +17,23 @@

# PSProfile - ChangeLog

## 0.4.0 - 2019-09-22

* [Issue #18](https://github.com/scrthq/PSProfile/issues/18)
* Added the following functions for Init Script management:
* `Add-PSProfileInitScript`
* `Get-PSProfileInitScript`
* `Remove-PSProfileInitScript`
* `Enable-PSProfileInitScript`
* `Disable-PSProfileInitScript`
* `Edit-PSProfileInitScript`
* Added contextual help file `about_PSProfile_Init_Scripts`
* Added Init Scripts section to `Start-PSProfileConfigurationHelper`
* Updated `PSProfile` class to include Init Script support.
* Miscellaneous
* Updated `Edit-PSProfilePrompt` when choosing to Save PSProfile to ensure the updated prompt is written back to disk.
* Updated `invoke.build.ps1` for better contextual verbosity when compiling the module during the build process.

## 0.3.0 - 2019-09-07

* [Issue #15](https://github.com/scrthq/PSProfile/issues/15)
Expand Down
69 changes: 68 additions & 1 deletion PSProfile/Classes/PSProfile.Classes.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class PSProfile {
[string[]] $PluginPaths
[string[]] $ProjectPaths
[hashtable] $Prompts
[hashtable] $InitScripts
[string[]] $ScriptPaths
[hashtable] $SymbolicLinks
[hashtable] $Variables
Expand Down Expand Up @@ -157,6 +158,7 @@ class PSProfile {
$this.LastRefresh = [datetime]::Now.AddHours(-2)
$this.ProjectPaths = @()
$this.PluginPaths = @()
$this.InitScripts = @{}
$this.ScriptPaths = @()
$this.PathAliases = @{
'~' = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::UserProfile)
Expand Down Expand Up @@ -235,7 +237,7 @@ if ($env:AWS_PROFILE) {
if ([String]::IsNullOrEmpty($awsIcon)) {
$awsIcon = "AWS:"
}
Write-Host -ForegroundColor Yellow "$($awsIcon) $($env:AWS_PROFILE)" -NoNewline
Write-Host -ForegroundColor Yellow "$($awsIcon) $($env:AWS_PROFILE)$(if($env:AWS_DEFAULT_REGION){" @ $env:AWS_DEFAULT_REGION"})" -NoNewline
Write-Host "]" -NoNewline
}
"`n>> "'
Expand Down Expand Up @@ -264,6 +266,7 @@ if ($env:AWS_PROFILE) {
"Verbose"
)
}
$this._invokeInitScripts()
$this._importModules()
$this._loadPlugins()
$this._invokeScripts()
Expand Down Expand Up @@ -292,6 +295,7 @@ if ($env:AWS_PROFILE) {
$this._installModules()
$this._createSymbolicLinks()
$this._formatPrompts()
$this._formatInitScripts()
$this.LastRefresh = [datetime]::Now
$this.Save()
}
Expand Down Expand Up @@ -410,6 +414,29 @@ if ($env:AWS_PROFILE) {
"Debug"
)
}
hidden [void] _formatInitScripts() {
$this._log(
"SECTION START",
"FormatInitScripts",
"Debug"
)
$final = $this.InitScripts
$this.InitScripts.GetEnumerator() | ForEach-Object {
$this._log(
"Formatting InitScript '$($_.Key)'",
"FormatInitScripts",
"Verbose"
)
$updated = ($_.Value.ScriptBlock -split "[\r\n]" | Where-Object { $_ }).Trim() -join "`n"
$final[$_.Key]['ScriptBlock'] = $updated
}
$this.InitScripts = $final
$this._log(
"SECTION END",
"FormatInitScripts",
"Debug"
)
}
hidden [void] _loadAdditionalConfiguration([string]$configurationPath) {
$this._log(
"SECTION START",
Expand Down Expand Up @@ -715,6 +742,46 @@ if ($env:AWS_PROFILE) {
'Debug'
)
}
hidden [void] _invokeInitScripts() {
$this._log(
"SECTION START",
"InvokeInitScripts",
"Debug"
)
$this.InitScripts.GetEnumerator() | ForEach-Object {
$s = $_
if ($_.Value.Enabled) {
$this._log(
"Invoking Init Script: $($s.Key)",
"InvokeInitScripts",
"Verbose"
)
try {
$sb = [scriptblock]::Create($this._globalize($s.Value.ScriptBlock))
.$sb
}
catch {
$this._log(
"Error while invoking InitScript '$($s.Key)': $($_.Exception.Message)",
"InvokeInitScripts",
"Warning"
)
}
}
else {
$this._log(
"Skipping disabled Init Script: $($_.Key)",
"InvokeInitScripts",
"Verbose"
)
}
}
$this._log(
"SECTION END",
"InvokeInitScripts",
"Debug"
)
}
hidden [void] _installModules() {
$this._log(
"SECTION START",
Expand Down
2 changes: 1 addition & 1 deletion PSProfile/PSProfile.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'PSProfile.psm1'

# Version number of this module.
ModuleVersion = '0.3.0'
ModuleVersion = '0.4.0'

# Supported PSEditions
CompatiblePSEditions = @('Desktop','Core')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,15 @@ function Start-PSProfileConfigurationHelper {
"[7] Project Paths"
"[8] Prompts"
"[9] Script Paths"
"[10] Secrets"
"[11] Symbolic Links"
"[12] Variables"
"[10] Init Scripts"
"[11] Secrets"
"[12] Symbolic Links"
"[13] Variables"
""
"[13] Power Tools"
"[14] Configuration"
"[15] Helpers"
"[16] Meta"
"[14] Power Tools"
"[15] Configuration"
"[16] Helpers"
"[17] Meta"
""
"[*] All concepts (Default)"
"[H] Hide Help Topics"
Expand Down Expand Up @@ -145,7 +146,7 @@ function Start-PSProfileConfigurationHelper {
"`nChoices:" | Write-Host
if ($choices -match '\*') {
$options | Select-String "^\[\*\]\s+" | Write-Host
$resolved = @(1..16)
$resolved = @(1..17)
if ($hideHelpTopics) {
$resolved += 'H'
}
Expand Down Expand Up @@ -501,6 +502,43 @@ function Start-PSProfileConfigurationHelper {
until ($decision -notmatch "[Yy]")
}
10 {
if ($Global:PSProfile.ScriptPaths.Count) {
.$current("`n- $(($Global:PSProfile.ScriptPaths | Sort-Object) -join "`n- ")")
}
Write-Host "Would you like to add an external script as an Init Script on your PSProfile?"
.$tip("Init Scripts are also invoked during PSProfile load. These differ from Script Paths in that the full script is stored on the PSProfile configuration itself. Init Scripts can also be disabled without being removed from PSProfile.")
.$tip("During this Configuration Helper, you are limited to providing a path to a script file to import as an Init Script. While using Add-PSProfileInitScript, however, you can provide a ScriptBlock or Strings of code directly if preferred.")
$decision = Read-Host "[Y] Yes [N] No [X] Exit"
do {
switch -Regex ($decision) {
"[Yy]" {
$item1 = Read-Host "Please enter the path of the script to import as Init Script"
if ($null -eq (Get-PSProfileInitScript -Name (Get-Item $item1).BaseName)) {
if (-not $changeHash.ContainsKey('Init Scripts')) {
$changes.Add("Init Scripts:")
$changeHash['Init Scripts'] = @()
}
.$command("Add-PSProfileInitScript -Path '$item1'")
Add-PSProfileInitScript -Path $item1 -Verbose
$changes.Add(" - $item1")
$changeHash['Init Scripts'] += $item1
}
else {
.$warning("Init Script '$item1' already exists on your PSProfile configuration! If you would like to overwrite it, run the following command:")
.$command("Add-PSProfileInitScript -Path '$item1' -Force")
}
"`nWould you like to import another Init Script to your PSProfile?" | Write-Host
$decision = Read-Host "[Y] Yes [N] No [X] Exit"
}
"[Xx]" {
.$exit
return
}
}
}
until ($decision -notmatch "[Yy]")
}
11 {
if (($Global:PSProfile.Vault._secrets.GetEnumerator() | Where-Object {$_.Key -ne 'GitCredentials'}).Count) {
.$current("`n- $((($Global:PSProfile.Vault._secrets.GetEnumerator() | Where-Object {$_.Key -ne 'GitCredentials'}).Key | Sort-Object) -join "`n- ")")
}
Expand Down Expand Up @@ -568,7 +606,7 @@ function Start-PSProfileConfigurationHelper {
}
until ($decision -notmatch "[Yy]")
}
11 {
12 {
if ($Global:PSProfile.SymbolicLinks.Keys.Count) {
.$current("`n$(($Global:PSProfile.SymbolicLinks | Out-String).Trim())")
}
Expand Down Expand Up @@ -605,7 +643,7 @@ function Start-PSProfileConfigurationHelper {
}
until ($decision -notmatch "[Yy]")
}
12 {
13 {
if ($Global:PSProfile.Variables.Environment.Keys.Count -or $Global:PSProfile.Variables.Global.Keys.Count) {
.$current("`n`n~~ ENVIRONMENT ~~`n$(($Global:PSProfile.Variables.Environment | Out-String).Trim())`n`n~~ GLOBAL ~~`n$(($Global:PSProfile.Variables.Global | Out-String).Trim())")
}
Expand Down Expand Up @@ -656,25 +694,25 @@ function Start-PSProfileConfigurationHelper {
}
until ($decision -notmatch "[Yy]")
}
13 {
14 {
"Power Tools functions do not alter the PSProfile configuration, so there is nothing to configure with this Helper! Please see the HelpTopic '$helpTopic' for more info:" | Write-Host
.$command("Get-Help $helpTopic")
"" | Write-Host
Read-Host "Press [Enter] to continue"
}
14 {
15 {
"Configuration functions are meant to interact with the PSProfile configuration directly, so there is nothing to configure with this Helper! Please see the HelpTopic '$helpTopic' for more info:" | Write-Host
.$command("Get-Help $helpTopic")
"" | Write-Host
Read-Host "Press [Enter] to continue"
}
15 {
16 {
"Helper functions are meant to interact for use within prompts or add Log Events to PSProfile, so there is nothing to configure with this Helper! Please see the HelpTopic '$helpTopic' for more info:" | Write-Host
.$command("Get-Help $helpTopic")
"" | Write-Host
Read-Host "Press [Enter] to continue"
}
16 {
17 {
"Meta functions are meant to provide information about PSProfile itself, so there is nothing to configure with this Helper! Please see the HelpTopic '$helpTopic' for more info:" | Write-Host
.$command("Get-Help $helpTopic")
"" | Write-Host
Expand Down
11 changes: 10 additions & 1 deletion PSProfile/Public/Configuration/Update-PSProfileSetting.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,16 @@ function Update-PSProfileSetting {
}
}

Register-ArgumentCompleter -CommandName 'Update-PSProfileSetting' -ParameterName Path -ScriptBlock {
Register-ArgumentCompleter -CommandName Update-PSProfileSetting -ParameterName Path -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
Get-PSProfileArguments @PSBoundParameters
}

Register-ArgumentCompleter -CommandName Update-PSProfileSetting -ParameterName Value -ScriptBlock {
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
if ($fakeBoundParameter.Path -eq 'Settings.FontType') {
@('Default','NerdFonts','PowerLine') | Where-Object {$_ -like "$wordToComplete*"} | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
}
Loading

0 comments on commit 4781379

Please sign in to comment.