-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.ps1
64 lines (57 loc) · 2.03 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
$VerbosePreference = 'Continue'
$profileFile = "Microsoft.PowerShell_profile.ps1"
Clear-Host
# Handling Profile creation
try {
# If a Profile already exists, rename it to $PROFILE.old
Write-Verbose "Testing if $PROFILE exists"
if (Test-Path -Path $PROFILE) {
Write-Verbose "$PROFILE found"
if ((Read-Host "$PROFILE.old already exists, if you continue it will overwrite it. Continue ? [y] or [Y]") -ne "y") { exit }
Move-Item -Path $PROFILE -Destination "$($PROFILE).old" -Force
Write-Verbose "Moved $PROFILE to $($PROFILE).old"
}
else {
Write-Verbose "$PROFILE not found"
}
# Windows PowerShell or PowerShell core
switch ($PSVersionTable.PSEdition) {
"Core" {
Write-Verbose "PowerShell core version"
$profilePath = "PowerShell"
}
"Desktop" {
Write-Verbose "Windows Powershell version"
$profilePath = "WindowsPowerShell"
}
Default {
Write-Host "Not on windows" -ForegroundColor Red
$profilePath = $null
}
}
# Creating a symlink to the new Profile if the path is not empty
if ($null -ne $profilePath) {
# Checking if it's the VSCode Powershell extension profile
if ($PROFILE.Contains("VSCode")) {
$profileFile = "Microsoft.VSCode_profile.ps1"
}
New-Item -ItemType SymbolicLink -Name $profileFile -Path "$($env:USERPROFILE)\Documents\$($profilePath)" -Target "$($PWD)\Microsoft.PowerShell_profile.ps1" -ErrorAction Stop
Write-Verbose "Created symlink at $PROFILE"
}
}
catch {
Write-Host $_.Exception.Message -ForegroundColor Red
}
try {
# Installing Starship
winget install -e --id Starship.Starship
Write-Verbose "Installed Starship"
# Installing Terminal Icons
Install-Module -Name Terminal-Icons -Repository PSGallery
Write-Verbose "Installed Terminal-Icons"
}
catch {
Write-Host $_.Exception.Message -ForegroundColor Red
}
# Refresh the Profile
. $PROFILE