Add scripts for editing the powershell profile
This commit is contained in:
parent
638d241973
commit
5055eddb82
2 changed files with 60 additions and 24 deletions
scripts/Common/Config/powershell
46
scripts/Common/Config/powershell/profile.ps1
Normal file
46
scripts/Common/Config/powershell/profile.ps1
Normal file
|
@ -0,0 +1,46 @@
|
|||
#!/bin/pwsh
|
||||
$null = New-Module {
|
||||
function Add-PowerShellProfileStatement() {
|
||||
param (
|
||||
[string]$HomeDir = "~",
|
||||
[string]$Category = $null,
|
||||
[Parameter(Position=0, Mandatory=$true)]
|
||||
[string]$Statement,
|
||||
[bool]$Overwrite = $false
|
||||
)
|
||||
|
||||
[System.Collections.Generic.List[string]] $profiles = @();
|
||||
|
||||
if (Get-Command pwsh) {
|
||||
$profiles.Add($(pwsh -c '$PROFILE'));
|
||||
}
|
||||
|
||||
if (Get-Command powershell) {
|
||||
$profiles.Add($(powershell -c '$PROFILE'));
|
||||
}
|
||||
|
||||
Push-Location ~;
|
||||
$profiles = $profiles | ForEach-Object { Resolve-Path -Relative $_ };
|
||||
|
||||
if ($Category) {
|
||||
$profiles = $profiles | ForEach-Object { Join-Path (Split-Path -Parent $_) "profile.d" "$Category.ps1"; };
|
||||
}
|
||||
|
||||
$profiles | ForEach-Object {
|
||||
$fileName = "$HomeDir/$_";
|
||||
$dirName = Split-Path -Parent $fileName;
|
||||
|
||||
if (-not (Test-Path -PathType Container $dirName)) {
|
||||
New-Item -ItemType Directory $dirName;
|
||||
}
|
||||
|
||||
if ((Test-Path -PathType Leaf $fileName) -and (-not $Overwrite)) {
|
||||
Add-Content -Force "$fileName" "`n$Statement";
|
||||
} else {
|
||||
Set-Content -Force "$fileName" "$Statement";
|
||||
}
|
||||
};
|
||||
|
||||
Pop-Location;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue