Skip to content

Commit 4781379

Browse files
committed
!deploy v0.4.0
## 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.
1 parent 5c6d66c commit 4781379

14 files changed

+604
-18
lines changed

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
* [PSProfile - ChangeLog](#psprofile---changelog)
2+
* [0.4.0 - 2019-09-22](#040---2019-09-22)
23
* [0.3.0 - 2019-09-07](#030---2019-09-07)
34
* [0.2.0 - 2019-09-02](#020---2019-09-02)
45
* [0.1.9 - 2019-08-26](#019---2019-08-26)
@@ -16,6 +17,23 @@
1617

1718
# PSProfile - ChangeLog
1819

20+
## 0.4.0 - 2019-09-22
21+
22+
* [Issue #18](https://github.com/scrthq/PSProfile/issues/18)
23+
* Added the following functions for Init Script management:
24+
* `Add-PSProfileInitScript`
25+
* `Get-PSProfileInitScript`
26+
* `Remove-PSProfileInitScript`
27+
* `Enable-PSProfileInitScript`
28+
* `Disable-PSProfileInitScript`
29+
* `Edit-PSProfileInitScript`
30+
* Added contextual help file `about_PSProfile_Init_Scripts`
31+
* Added Init Scripts section to `Start-PSProfileConfigurationHelper`
32+
* Updated `PSProfile` class to include Init Script support.
33+
* Miscellaneous
34+
* Updated `Edit-PSProfilePrompt` when choosing to Save PSProfile to ensure the updated prompt is written back to disk.
35+
* Updated `invoke.build.ps1` for better contextual verbosity when compiling the module during the build process.
36+
1937
## 0.3.0 - 2019-09-07
2038

2139
* [Issue #15](https://github.com/scrthq/PSProfile/issues/15)

PSProfile/Classes/PSProfile.Classes.ps1

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class PSProfile {
107107
[string[]] $PluginPaths
108108
[string[]] $ProjectPaths
109109
[hashtable] $Prompts
110+
[hashtable] $InitScripts
110111
[string[]] $ScriptPaths
111112
[hashtable] $SymbolicLinks
112113
[hashtable] $Variables
@@ -157,6 +158,7 @@ class PSProfile {
157158
$this.LastRefresh = [datetime]::Now.AddHours(-2)
158159
$this.ProjectPaths = @()
159160
$this.PluginPaths = @()
161+
$this.InitScripts = @{}
160162
$this.ScriptPaths = @()
161163
$this.PathAliases = @{
162164
'~' = [System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::UserProfile)
@@ -235,7 +237,7 @@ if ($env:AWS_PROFILE) {
235237
if ([String]::IsNullOrEmpty($awsIcon)) {
236238
$awsIcon = "AWS:"
237239
}
238-
Write-Host -ForegroundColor Yellow "$($awsIcon) $($env:AWS_PROFILE)" -NoNewline
240+
Write-Host -ForegroundColor Yellow "$($awsIcon) $($env:AWS_PROFILE)$(if($env:AWS_DEFAULT_REGION){" @ $env:AWS_DEFAULT_REGION"})" -NoNewline
239241
Write-Host "]" -NoNewline
240242
}
241243
"`n>> "'
@@ -264,6 +266,7 @@ if ($env:AWS_PROFILE) {
264266
"Verbose"
265267
)
266268
}
269+
$this._invokeInitScripts()
267270
$this._importModules()
268271
$this._loadPlugins()
269272
$this._invokeScripts()
@@ -292,6 +295,7 @@ if ($env:AWS_PROFILE) {
292295
$this._installModules()
293296
$this._createSymbolicLinks()
294297
$this._formatPrompts()
298+
$this._formatInitScripts()
295299
$this.LastRefresh = [datetime]::Now
296300
$this.Save()
297301
}
@@ -410,6 +414,29 @@ if ($env:AWS_PROFILE) {
410414
"Debug"
411415
)
412416
}
417+
hidden [void] _formatInitScripts() {
418+
$this._log(
419+
"SECTION START",
420+
"FormatInitScripts",
421+
"Debug"
422+
)
423+
$final = $this.InitScripts
424+
$this.InitScripts.GetEnumerator() | ForEach-Object {
425+
$this._log(
426+
"Formatting InitScript '$($_.Key)'",
427+
"FormatInitScripts",
428+
"Verbose"
429+
)
430+
$updated = ($_.Value.ScriptBlock -split "[\r\n]" | Where-Object { $_ }).Trim() -join "`n"
431+
$final[$_.Key]['ScriptBlock'] = $updated
432+
}
433+
$this.InitScripts = $final
434+
$this._log(
435+
"SECTION END",
436+
"FormatInitScripts",
437+
"Debug"
438+
)
439+
}
413440
hidden [void] _loadAdditionalConfiguration([string]$configurationPath) {
414441
$this._log(
415442
"SECTION START",
@@ -715,6 +742,46 @@ if ($env:AWS_PROFILE) {
715742
'Debug'
716743
)
717744
}
745+
hidden [void] _invokeInitScripts() {
746+
$this._log(
747+
"SECTION START",
748+
"InvokeInitScripts",
749+
"Debug"
750+
)
751+
$this.InitScripts.GetEnumerator() | ForEach-Object {
752+
$s = $_
753+
if ($_.Value.Enabled) {
754+
$this._log(
755+
"Invoking Init Script: $($s.Key)",
756+
"InvokeInitScripts",
757+
"Verbose"
758+
)
759+
try {
760+
$sb = [scriptblock]::Create($this._globalize($s.Value.ScriptBlock))
761+
.$sb
762+
}
763+
catch {
764+
$this._log(
765+
"Error while invoking InitScript '$($s.Key)': $($_.Exception.Message)",
766+
"InvokeInitScripts",
767+
"Warning"
768+
)
769+
}
770+
}
771+
else {
772+
$this._log(
773+
"Skipping disabled Init Script: $($_.Key)",
774+
"InvokeInitScripts",
775+
"Verbose"
776+
)
777+
}
778+
}
779+
$this._log(
780+
"SECTION END",
781+
"InvokeInitScripts",
782+
"Debug"
783+
)
784+
}
718785
hidden [void] _installModules() {
719786
$this._log(
720787
"SECTION START",

PSProfile/PSProfile.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
RootModule = 'PSProfile.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '0.3.0'
15+
ModuleVersion = '0.4.0'
1616

1717
# Supported PSEditions
1818
CompatiblePSEditions = @('Desktop','Core')

PSProfile/Public/Configuration/Start-PSProfileConfigurationHelper.ps1

Lines changed: 52 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,15 @@ function Start-PSProfileConfigurationHelper {
9393
"[7] Project Paths"
9494
"[8] Prompts"
9595
"[9] Script Paths"
96-
"[10] Secrets"
97-
"[11] Symbolic Links"
98-
"[12] Variables"
96+
"[10] Init Scripts"
97+
"[11] Secrets"
98+
"[12] Symbolic Links"
99+
"[13] Variables"
99100
""
100-
"[13] Power Tools"
101-
"[14] Configuration"
102-
"[15] Helpers"
103-
"[16] Meta"
101+
"[14] Power Tools"
102+
"[15] Configuration"
103+
"[16] Helpers"
104+
"[17] Meta"
104105
""
105106
"[*] All concepts (Default)"
106107
"[H] Hide Help Topics"
@@ -145,7 +146,7 @@ function Start-PSProfileConfigurationHelper {
145146
"`nChoices:" | Write-Host
146147
if ($choices -match '\*') {
147148
$options | Select-String "^\[\*\]\s+" | Write-Host
148-
$resolved = @(1..16)
149+
$resolved = @(1..17)
149150
if ($hideHelpTopics) {
150151
$resolved += 'H'
151152
}
@@ -501,6 +502,43 @@ function Start-PSProfileConfigurationHelper {
501502
until ($decision -notmatch "[Yy]")
502503
}
503504
10 {
505+
if ($Global:PSProfile.ScriptPaths.Count) {
506+
.$current("`n- $(($Global:PSProfile.ScriptPaths | Sort-Object) -join "`n- ")")
507+
}
508+
Write-Host "Would you like to add an external script as an Init Script on your PSProfile?"
509+
.$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.")
510+
.$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.")
511+
$decision = Read-Host "[Y] Yes [N] No [X] Exit"
512+
do {
513+
switch -Regex ($decision) {
514+
"[Yy]" {
515+
$item1 = Read-Host "Please enter the path of the script to import as Init Script"
516+
if ($null -eq (Get-PSProfileInitScript -Name (Get-Item $item1).BaseName)) {
517+
if (-not $changeHash.ContainsKey('Init Scripts')) {
518+
$changes.Add("Init Scripts:")
519+
$changeHash['Init Scripts'] = @()
520+
}
521+
.$command("Add-PSProfileInitScript -Path '$item1'")
522+
Add-PSProfileInitScript -Path $item1 -Verbose
523+
$changes.Add(" - $item1")
524+
$changeHash['Init Scripts'] += $item1
525+
}
526+
else {
527+
.$warning("Init Script '$item1' already exists on your PSProfile configuration! If you would like to overwrite it, run the following command:")
528+
.$command("Add-PSProfileInitScript -Path '$item1' -Force")
529+
}
530+
"`nWould you like to import another Init Script to your PSProfile?" | Write-Host
531+
$decision = Read-Host "[Y] Yes [N] No [X] Exit"
532+
}
533+
"[Xx]" {
534+
.$exit
535+
return
536+
}
537+
}
538+
}
539+
until ($decision -notmatch "[Yy]")
540+
}
541+
11 {
504542
if (($Global:PSProfile.Vault._secrets.GetEnumerator() | Where-Object {$_.Key -ne 'GitCredentials'}).Count) {
505543
.$current("`n- $((($Global:PSProfile.Vault._secrets.GetEnumerator() | Where-Object {$_.Key -ne 'GitCredentials'}).Key | Sort-Object) -join "`n- ")")
506544
}
@@ -568,7 +606,7 @@ function Start-PSProfileConfigurationHelper {
568606
}
569607
until ($decision -notmatch "[Yy]")
570608
}
571-
11 {
609+
12 {
572610
if ($Global:PSProfile.SymbolicLinks.Keys.Count) {
573611
.$current("`n$(($Global:PSProfile.SymbolicLinks | Out-String).Trim())")
574612
}
@@ -605,7 +643,7 @@ function Start-PSProfileConfigurationHelper {
605643
}
606644
until ($decision -notmatch "[Yy]")
607645
}
608-
12 {
646+
13 {
609647
if ($Global:PSProfile.Variables.Environment.Keys.Count -or $Global:PSProfile.Variables.Global.Keys.Count) {
610648
.$current("`n`n~~ ENVIRONMENT ~~`n$(($Global:PSProfile.Variables.Environment | Out-String).Trim())`n`n~~ GLOBAL ~~`n$(($Global:PSProfile.Variables.Global | Out-String).Trim())")
611649
}
@@ -656,25 +694,25 @@ function Start-PSProfileConfigurationHelper {
656694
}
657695
until ($decision -notmatch "[Yy]")
658696
}
659-
13 {
697+
14 {
660698
"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
661699
.$command("Get-Help $helpTopic")
662700
"" | Write-Host
663701
Read-Host "Press [Enter] to continue"
664702
}
665-
14 {
703+
15 {
666704
"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
667705
.$command("Get-Help $helpTopic")
668706
"" | Write-Host
669707
Read-Host "Press [Enter] to continue"
670708
}
671-
15 {
709+
16 {
672710
"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
673711
.$command("Get-Help $helpTopic")
674712
"" | Write-Host
675713
Read-Host "Press [Enter] to continue"
676714
}
677-
16 {
715+
17 {
678716
"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
679717
.$command("Get-Help $helpTopic")
680718
"" | Write-Host

PSProfile/Public/Configuration/Update-PSProfileSetting.ps1

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,16 @@ function Update-PSProfileSetting {
9494
}
9595
}
9696

97-
Register-ArgumentCompleter -CommandName 'Update-PSProfileSetting' -ParameterName Path -ScriptBlock {
97+
Register-ArgumentCompleter -CommandName Update-PSProfileSetting -ParameterName Path -ScriptBlock {
9898
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
9999
Get-PSProfileArguments @PSBoundParameters
100100
}
101+
102+
Register-ArgumentCompleter -CommandName Update-PSProfileSetting -ParameterName Value -ScriptBlock {
103+
param($commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameter)
104+
if ($fakeBoundParameter.Path -eq 'Settings.FontType') {
105+
@('Default','NerdFonts','PowerLine') | Where-Object {$_ -like "$wordToComplete*"} | ForEach-Object {
106+
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
107+
}
108+
}
109+
}

0 commit comments

Comments
 (0)