-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreateSymlinks.ps1
43 lines (36 loc) · 1.35 KB
/
CreateSymlinks.ps1
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
# Get the ID and security principal of the current user account
$myWindowsID = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$myWindowsPrincipal = new-object System.Security.Principal.WindowsPrincipal($myWindowsID)
# Get the security principal for the Administrator role
$adminRole = [System.Security.Principal.WindowsBuiltInRole]::Administrator
# Check to see if we are currently running "as Administrator"
if ($myWindowsPrincipal.IsInRole($adminRole)) {
$srcDir = (Get-Location).Path
$emacsAppDataDir = Join-Path -Path $env:APPDATA -ChildPath ".emacs.d"
$emacsHomeDir = Join-Path -Path (Resolve-Path ~).Path -ChildPath ".emacs.d"
if (! (Test-Path $emacsAppDataDir)) {
New-Item -ItemType Directory -Path $emacsAppDataDir
}
if (! (Test-Path $emacsHomeDir)) {
New-Item -ItemType Directory -Path $emacsHomeDir
}
function New-SymLink {
param (
$FileName,
$TargetDir
)
$srcFile = Join-Path -Path $srcDir -ChildPath $FileName
$tgtFile = Join-Path -Path $targetDir -ChildPath $FileName
if (Test-Path $tgtFile) {
Write-Error "File already exists! [$tgtFile]"
}
else {
New-Item -ItemType SymbolicLink -Path $tgtFile -Value $srcFile
}
}
New-SymLink -FileName .\init.el -TargetDir $emacsAppDataDir
New-SymLink -FileName .\early-init.el -TargetDir $emacsAppDataDir
}
else {
Write-Error "This script requires Admin Privileges"
}