-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdotenv.ps1
More file actions
68 lines (60 loc) · 1.63 KB
/
dotenv.ps1
File metadata and controls
68 lines (60 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Define the path to the PowerShell profile
$profilePath = $PROFILE
# Define the lines we want to add
$linesToAdd = @(
'. $Env:USERPROFILE\.env\inc\git-aliases.ps1',
'. $Env:USERPROFILE\.env\inc\prompt.ps1'
)
function Add-LineIfNotExists {
param (
[string]$FilePath,
[string]$Line
)
if (-not (Test-Path $FilePath)) {
New-Item -Path $FilePath -ItemType File -Force | Out-Null
Write-Host "Created new profile file: $FilePath"
}
$content = Get-Content $FilePath -ErrorAction SilentlyContinue
if ($content -notcontains $Line) {
Add-Content -Path $FilePath -Value $Line
Write-Host "Added line to profile: $Line"
}
else {
Write-Host "Line already exists in profile: $Line"
}
}
function Patch-Profile {
Write-Host "Patching PowerShell profile..."
foreach ($line in $linesToAdd) {
Add-LineIfNotExists -FilePath $profilePath -Line $line
}
Write-Host "Profile patching complete."
}
function Print-Usage {
Write-Host "Usage: .\ManagePowerShellProfile.ps1 [patch]"
Write-Host " patch: Patch the PowerShell profile"
Write-Host " If no argument is provided, patch will be executed by default."
}
# Main script execution
if ($args.Count -eq 0) {
Patch-Profile
}
else {
switch ($args[0].ToLower()) {
"patch" {
Patch-Profile
}
"-h" {
Print-Usage
}
"--help" {
Print-Usage
}
"--usage" {
Print-Usage
}
default {
Write-Host "Invalid argument. Use -h or --help for usage information."
}
}
}