-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathsetup.ps1
More file actions
69 lines (59 loc) · 2.21 KB
/
setup.ps1
File metadata and controls
69 lines (59 loc) · 2.21 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
69
#Requires -Version 5.1
<#
.SYNOPSIS
Install eMerger on Windows: register the `up` function, ensure execution
policy allows it, scaffold %APPDATA%\emerger.
#>
[CmdletBinding()]
param()
$ErrorActionPreference = 'Stop'
$REPO = Split-Path -Parent $PSCommandPath
. "$REPO\src\pslib\UI.ps1"
. "$REPO\src\pslib\Sys.ps1"
UI-Title 'eMerger setup (Windows)'
# ExecutionPolicy fix.
$ep = Get-ExecutionPolicy -Scope CurrentUser
if ($ep -eq 'Restricted' -or $ep -eq 'Undefined') {
UI-Info "ExecutionPolicy is '$ep'; setting to RemoteSigned for CurrentUser."
try {
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned -Force
UI-Ok 'ExecutionPolicy updated.'
} catch {
UI-Warn "Could not change ExecutionPolicy: $($_.Exception.Message)"
}
}
# PowerShell profile: add `up` function.
$profilePath = $PROFILE.CurrentUserAllHosts
$profileDir = Split-Path $profilePath
if (-not (Test-Path $profileDir)) { New-Item -ItemType Directory -Path $profileDir -Force | Out-Null }
if (-not (Test-Path $profilePath)) { New-Item -ItemType File -Path $profilePath -Force | Out-Null }
$entry = "$REPO\src\emerger.ps1"
$existing = Get-Content $profilePath -Raw -ErrorAction SilentlyContinue
if ($existing -and $existing -match 'emerger\.ps1') {
UI-Ok "'up' already registered in $profilePath"
} else {
$block = @"
# eMerger (https://github.com/MasterCruelty/eMerger)
function up { & "$entry" @args }
"@
Add-Content -Path $profilePath -Value $block
UI-Ok "Added 'up' function to $profilePath"
}
# Config + hooks + profiles skeleton.
$cfg = Join-Path $env:APPDATA 'emerger'
@('hooks\pre.d','hooks\post.d','profiles.d') | ForEach-Object {
$p = Join-Path $cfg $_
if (-not (Test-Path $p)) { New-Item -ItemType Directory -Path $p -Force | Out-Null }
}
$configFile = Join-Path $cfg 'config.ps1'
if (-not (Test-Path $configFile)) {
@'
# eMerger user config (Windows). Dot-sourced before argument parsing.
# Uncomment to set defaults.
# $script:ArgsGlobal.Dev = $true
# $script:ArgsGlobal.NoTrash = $true
# $script:ArgsGlobal.Security = $true
'@ | Set-Content $configFile -Encoding UTF8
UI-Ok "Created $configFile"
}
UI-Info "Open a new PowerShell window (or: . `$PROFILE) and run: up --help"