-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSetup.ps1
124 lines (93 loc) · 3.22 KB
/
Setup.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
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#Requires -RunAsAdministrator
$profileDir = (Split-Path $PROFILE)
$onOneDrive = $profileDir -like "*OneDrive*"
if ($onOneDrive) {
Write-Warning "Powershell profile is in a OneDrive folder. As a result, symbolink links will not be created - files will be copied instead."
}
function New-SymLink {
[cmdletbinding()]
param(
[parameter(Mandatory = $true, ValueFromPipeline = $true)]
[string]
$target)
process {
$filePath = Resolve-Path $target -Relative
Write-Host $filePath
$pathToWrite = (Join-Path -Path $profileDir -ChildPath $filePath)
Write-Host $pathToWrite
if (-not (Test-Path $profileDir)) {
New-Item -ItemType Directory -Path $profileDir -Force | Out-Null
}
if (-not (Test-Path $pathToWrite)) {
New-Item -ItemType SymbolicLink -Target $target -Path $pathToWrite
}
}
}
function CopyOrCreateSymLink {
[cmdletbinding()]
param(
[parameter(Mandatory = $true, ValueFromPipeline = $true)]
[string]
$target)
process {
$filePath = Resolve-Path $target -Relative
$pathToWrite = (Join-Path -Path $profileDir -ChildPath $filePath)
if (-not (Test-Path $pathToWrite)) {
if ($onOneDrive) {
New-Item -ItemType Directory -Path $profileDir -Force | Out-Null
Copy-Item -Path $filePath -Destination $pathToWrite
}
else {
New-Item -ItemType SymbolicLink -Target $target -Path $pathToWrite
}
}
else {
Write-Warning "$pathToWrite to exists already. Skipping"
}
}
}
function Copy-Scripts {
Get-ChildItem | Where-Object { $_.Extension -eq ".ps1" } | Where-Object { $_.FullName -ne $PSCommandPath } | CopyOrCreateSymLink
}
function Copy-OhMyPoshTheme {
Get-ChildItem | Where-Object { $_.Name -contains "omp.json" } | CopyOrCreateSymLink
}
function Install-Modules {
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted
if (!(Get-Module -ListAvailable -Name "oh-my-posh")) {
Install-Module oh-my-posh
}
if (!(Get-Module -ListAvailable -Name "posh-git")) {
Install-Module posh-git
}
if (!(Get-Module -ListAvailable -Name "PSScriptTools")) {
Install-Module PSScriptTools
}
if (!(Get-Module -ListAvailable -Name "PSReadLine")) {
Install-Module PSReadLine -AllowPrerelease
}
if (!(Get-Module -ListAvailable -Name "Terminal-Icons")) {
Install-Module Terminal-Icons
}
if (!(Get-Module -ListAvailable -Name "z")) {
Install-Module z
}
if (!(Get-Module -ListAvailable -Name "npm-completion")) {
Install-Module npm-completion -Scope CurrentUser
}
}
function Copy-GitConfig {
param(
[parameter(Mandatory = $true)]
[string] $email,
[parameter(Mandatory = $true)]
[string] $fullName)
Get-Content -Path ".\.gitconfig" | ForEach-Object {
$_ -Replace '\$email\$', $email `
-Replace '\$name\$', $fullName
} | Set-Content "~\.gitconfig"
}
Install-Modules
Copy-Scripts
Copy-GitConfig
Copy-OhMyPoshTheme