Refactor creation of powershell profile
This commit is contained in:
parent
10a96402fe
commit
f90e849661
1 changed files with 9 additions and 3 deletions
|
@ -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)) {
|
||||
|
|
Loading…
Reference in a new issue