Refactor creation of powershell profile

This commit is contained in:
Manuel Thalmann 2024-03-20 18:49:56 +01:00
parent 325371140e
commit 4142ee97db

View file

@ -9,14 +9,20 @@ $null = New-Module {
[bool]$Overwrite = $false
)
[System.Collections.Generic.List[string]] $shells = @();
[System.Collections.Generic.List[string]] $profiles = @();
if (Get-Command pwsh -ErrorAction SilentlyContinue) {
$profiles.Add($(pwsh -c '$PROFILE'));
$shells.Add("pwsh");
}
if (Get-Command powershell -ErrorAction SilentlyContinue) {
$profiles.Add($(powershell -c '$PROFILE'));
$shells.Add("powershell");
}
foreach ($shell in $shells) {
$path = & $shell -NoProfile -c '$PROFILE';
$profiles.Add($path);
}
Push-Location ~;
@ -31,7 +37,7 @@ $null = New-Module {
$dirName = Split-Path -Parent $fileName;
if (-not (Test-Path -PathType Container $dirName)) {
$null = New-Item -ItemType Directory $dirName;
$null = New-Item -ItemType Directory -Force $dirName;
}
if ((Test-Path -PathType Leaf $fileName) -and (-not $Overwrite)) {