From 0a44ce6bdec83cc8af4121a0d8b9582452a808da Mon Sep 17 00:00:00 2001 From: Jimmy Briggs Date: Wed, 17 Jan 2024 18:49:39 -0500 Subject: [PATCH] add PSProfile.Modules for #16 --- PSProfile/PSProfile.Modules.ps1 | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 PSProfile/PSProfile.Modules.ps1 diff --git a/PSProfile/PSProfile.Modules.ps1 b/PSProfile/PSProfile.Modules.ps1 new file mode 100644 index 0000000..0f9cd88 --- /dev/null +++ b/PSProfile/PSProfile.Modules.ps1 @@ -0,0 +1,42 @@ +# Alternate PSModulesPath (User) +if ($isWindows) { + $LocalAppDataModulePath = Join-Path -Path $env:LOCALAPPDATA -ChildPath 'PowerShell\Modules' + if (-not(Test-Path -Path $LocalAppDataModulePath)) { + New-Item -Path $LocalAppDataModulePath -ItemType Directory -Force + } + # Add to Start of PSModulePath + $env:PSModulePath = $LocalAppDataModulePath + [IO.Path]::PathSeparator + $env:PSModulePath +} + +$ProfileModulesToImport = @( + 'PSReadLine' + 'posh-git' + 'Terminal-Icons' + 'PSFzf' + 'PSEverything' + 'CompletionPredictor' + 'Microsoft.PowerShell.ConsoleGuiTools' + 'F7History' +) + +ForEach ($Mod in $ProfileModulesToImport) { + try { + Write-Verbose "Importing Module: $Mod" + Import-Module $Mod -ErrorAction Stop + } catch { + Write-Warning "Failed to install module: $Mod" + try { + Install-PSResource $Mod -Scope CurrentUser -Force -ErrorAction Stop + } catch { + Write-Warning "Failed to install module: $Mod" + Continue + } + } finally { + Import-Module -Name $Mod -ErrorAction SilentlyContinue + } +} + +if (Get-PSResource -Name ZLocation) { + Import-Module ZLocation + Write-Host -Foreground Green "`n[ZLocation] knows about $((Get-ZLocation).Keys.Count) locations.`n" +}