-
Notifications
You must be signed in to change notification settings - Fork 0
/
install-shortcuts.ps1
executable file
·209 lines (176 loc) · 6.61 KB
/
install-shortcuts.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
<#
.SYNOPSIS
This script is used to create SymbolicLinks from the configuration files in this repository to their OS respective locations.
.DESCRIPTION
By creating SymbolicLinks from the configuration files in this repository to their OS respective locations, the expected development environment is created.
.LINK
https://github.com/Renegade-Master/dotfiles
.PARAMETER DryRun
If present, the script will not actually create the SymbolicLinks.
This is useful for viewing the potentially affected files.
.EXAMPLE
$ ./install-shortcuts.ps1
.EXAMPLE
$ ./install-shortcuts.ps1 -DryRun
#>
Param (
[ Parameter(Mandatory = $false) ]
[ Switch ]$DryRun
)
[ Hashtable ]$Config = @{
"Fleet" = @{
"Main" = "$( $pwd.Path )/editors/fleet/settings.json"
"Windows" = "$( $env:USERPROFILE )\\.fleet\\settings.json"
"Linux" = "$( $env:HOME )/.fleet/settings.json"
}
"GitConfig" = @{
"Main" = "$( $pwd.Path )/.gitconfig"
"Windows" = "$( $env:USERPROFILE )\\.gitconfig"
"Linux" = "$( $env:HOME )/.gitconfig"
}
"GitIgnore" = @{
"Main" = "$( $pwd.Path )/.gitignore"
"Windows" = "$( $env:USERPROFILE )\\.gitignore"
"Linux" = "$( $env:HOME )/.gitignore"
}
"HTOP" = @{
"Main" = "$( $pwd.Path )/.config/htop/htoprc"
"Windows" = "NOT_APPLICABLE"
"Linux" = "$( $env:HOME )/.config/htop/htoprc"
}
"NuShell CONFIG" = @{
"Main" = "$( $pwd.Path )/.config/nushell/config.nu"
"Windows" = "$( $env:AppData )\\nushell\\config.nu"
"Linux" = "NOT_APPLICABLE"
}
"NuShell ENV" = @{
"Main" = "$( $pwd.Path )/.config/nushell/env.nu"
"Windows" = "$( $env:AppData )\\nushell\\env.nu"
"Linux" = "NOT_APPLICABLE"
}
"NVIM" = @{
"Main" = "$( $pwd.Path )/editors/nvim/"
"Windows" = "$( $env:LocalAppData )\\nvim\\"
"Linux" = "$( $env:HOME )/.config/nvim/"
}
"PowerShell" = @{
"Main" = "$( $pwd.Path )/.config/powershell/Microsoft.PowerShell_profile.ps1"
"Windows" = "$Profile"
"Linux" = "$Profile"
}
"Tmux" = @{
"Main" = "$( $pwd.Path )/.tmux.conf"
"Windows" = "NOT_APPLICABLE"
"Linux" = "$( $env:HOME )/.tmux.conf"
}
"UserConfig" = @{
"Main" = "$( $pwd.Path )/.usrrc"
"Windows" = "NOT_APPLICABLE"
"Linux" = "$( $env:HOME )/.usrrc"
}
"Vim" = @{
"Main" = "$( $pwd.Path )/.vimrc"
"Windows" = "$( $env:USERPROFILE )\\.vimrc"
"Linux" = "$( $env:HOME )/.vimrc"
}
"VS Codium" = @{
"Main" = "$( $pwd.Path )/editors/vscodium/settings.json"
"Windows" = "$( $env:AppData )\\VSCodium\\User\\settings.json"
"Linux" = "$( $env:HOME )/.config/VSCodium/User/settings.json"
}
"WindowsTerminal" = @{
"Main" = "$( $pwd.Path )/terminals/windows-terminal/settings.json"
"Windows" = "$( $env:LocalAppData )\\Packages\\Microsoft.WindowsTerminal_8wekyb3d8bbwe\\LocalState\\settings.json"
"Linux" = "NOT_APPLICABLE"
}
"WindowsTerminalPreview" = @{
"Main" = "$( $pwd.Path )/terminals/windows-terminal/settings.json"
"Windows" = "$( $env:LocalAppData )\\Packages\\Microsoft.WindowsTerminalPreview_8wekyb3d8bbwe\\LocalState\\settings.json"
"Linux" = "NOT_APPLICABLE"
}
"Winget" = @{
"Main" = "$( $pwd.Path )/package-managers/winget/settings.json"
"Windows" = "$( $env:LocalAppData )\\Packages\\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\\LocalState\\settings.json"
"Linux" = "NOT_APPLICABLE"
}
}
<#
.SYNOPSIS
Take a Target and Source file, and create a SymbolicLink from the Source to the Target.
.PARAMETER LinkFile
The Source file to link the Target reference to.
.PARAMETER TargetFile
The Target file that the Reference will link to.
.PARAMETER DryRun
When set to true, will add '-WhatIf' to New-Item command.
.PARAMETER Force
When set to true, will add '-Force' to New-Item command.
.EXAMPLE
New-ConfigurationFile -LinkFile "$( $env:USERPROFILE )\\.gitconfig" -TargetFile "$( $pwd.Path )/.gitconfig"
.EXAMPLE
New-ConfigurationFile -LinkFile "$( $env:USERPROFILE )\\.gitconfig" -TargetFile "$( $pwd.Path )/.gitconfig" -DryRun $true
#>
Function New-ConfigurationFile {
Param (
[ Parameter(Mandatory = $true) ]
[ String ]$LinkFile,
[ Parameter(Mandatory = $true) ]
[ String ]$TargetFile,
[ Parameter(Mandatory = $false) ]
[ Boolean ]$DryRun,
[ Parameter(Mandatory = $false) ]
[ Switch ]$Force
)
Write-Host "Executing command: [ New-Item -Type SymbolicLink -Path $LinkFile -Target $TargetFile ]"
if ($DryRun -and $Force) {
New-Item -Type SymbolicLink -Path "$LinkFile" -Target "$TargetFile" -Force -WhatIf
} elseif ($DryRun) {
New-Item -Type SymbolicLink -Path "$LinkFile" -Target "$TargetFile" -WhatIf
} elseif ($Force) {
New-Item -Type SymbolicLink -Path "$LinkFile" -Target "$TargetFile" -Force
} else {
New-Item -Type SymbolicLink -Path "$LinkFile" -Target "$TargetFile"
}
}
Function New-ConfigurationFiles {
Param (
[ Parameter(Mandatory = $false) ]
[ Boolean ]$DryRun
)
$HostOs = "DEFAULT"
if ( $PSVersionTable.OS.Contains("Windows")) {
$HostOs = "Windows"
}
if ( $PSVersionTable.OS.Contains("Linux")) {
$HostOs = "Linux"
}
if ($HostOs -eq "DEFAULT") {
Throw "E: Host Operating System indeterminate. [$PSVersionTable]"
}
Write-Host "Linking $HostOs configuration files..."
ForEach ($Replacement in $Config.Keys) {
$app = $Config.$Replacement
if ($app.$HostOs -eq "NOT_APPLICABLE") {
continue
}
Write-Host "`nLinking $( $Replacement ): [$( $Config.$Replacement.$HostOs )] to [$( $Config.$Replacement.Main )]."
New-ConfigurationFile `
-LinkFile $( $Config.$Replacement.$HostOs ) `
-TargetFile $( $Config.$Replacement.Main ) `
-DryRun $DryRun `
-ErrorAction SilentlyContinue -ErrorVariable ProcessError
if ($ProcessError) {
Write-Error "Error: $ProcessError"
$continue = Read-Host "That didn't appear to work. Would you like to attempt to force the operation? Y/N"
if ($continue -eq "Y" -or $continue -eq "y") {
New-ConfigurationFile `
-LinkFile $( $Config.$Replacement.$HostOs ) `
-TargetFile $( $Config.$Replacement.Main ) `
-DryRun $DryRun `
-Force
}
}
}
}
## Main Method ##
New-ConfigurationFiles -DryRun $DryRun