This repository has been archived by the owner on Apr 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.ps1
139 lines (119 loc) · 4.92 KB
/
install.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
# requires -v 3
$urlOfTheme = "https://raw.githubusercontent.com/bibistroc/ConEmu-environment/master/Theme/HonukaiAlt.psm1"
# check for powershell version
if(($PSVersionTable.PSVersion.Major) -lt 3) {
Write-Output "PowerShell 3 or greater is required to use this profile."
Write-Output "Upgrade PowerShell: https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell"
break
}
# check for execution policy:
if((Get-ExecutionPolicy) -gt 'RemoteSigned' -or (Get-ExecutionPolicy) -eq 'ByPass') {
Write-Output "PowerShell requires an execution policy of 'RemoteSigned' to configure this profile."
Write-Output "To make this change please run:"
Write-Output "'Set-ExecutionPolicy RemoteSigned -scope CurrentUser'"
break
}
function Show-Exit {
Write-Host "Press any key to exit..."
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
break
}
function Install-Conemu {
Write-Host "This script is not run from ConEmu."
Write-Host "If you have ConEmu installed, quit now and run this script from it."
$installConemu = Read-Host -Prompt "Do you want to install ConEmu? [Y/q]"
if ($installConemu -like "y" -or $installConemu -eq "") {
# Installation script from https://conemu.github.io/en/AutoInstall.html
Start-Process powershell `
-ArgumentList "-Command iex ((new-object net.webclient).DownloadString('https://conemu.github.io/install.ps1'))" `
-Wait
Write-Host "ConEmu installed"
Write-Host "You can start ConEmu and run this script again from it to continue."
Show-Exit
} else {
Write-Host "ConEmu is required for this to work properly."
Write-Host "If you want to use it, you can run this script again."
Show-Exit
}
}
function Install-Git {
Write-Host "Git is not installed."
$installGit = Read-Host -Prompt "Do you want to install it? [Y/n]"
if ($installGit -like "y" -or $installGit -eq "") {
Write-Host "In order to install git, an external script will be run."
Write-Host "If you want to inspect the script, you can find it here: "
Write-Host "http://r.gbarbu.eu/installgit"
Write-Host "Press [ENTER] to continue or [CTRL+C] to cancel."
Read-Host
Write-Host "Starting installing"
Start-Process powershell `
-ArgumentList "-Command iwr r.gbarbu.eu/installgit -UseBasicParsing | iex" `
-Wait
Write-Host "Git installed"
# Reset environment variables
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" +
[System.Environment]::GetEnvironmentVariable("Path","User")
} else {
Write-Host "Git is required for this to work properly."
Write-Host "If you want to use it, you can run this script again."
Show-Exit
}
}
# check for prerequisites
try {
IsConEmu | Out-Null
} catch {
Install-Conemu
}
try {
git | Out-Null
} catch {
Install-Git
}
# checking for required powershell modules
Write-Host "Checking for required powershell modules"
if (-not (Get-Module -name posh-git)) {
Install-Module posh-git -Scope CurrentUser -Force -SkipPublisherCheck
} else {
Write-Host "posh-git module is installed"
}
if (-not (Get-Module -name oh-my-posh)) {
Install-Module oh-my-posh -Scope CurrentUser -Force -SkipPublisherCheck
} else {
Write-Host "oh-my-posh module is installed"
}
if (-not (Get-Module -name posh-docker)) {
Install-Module posh-docker -Scope CurrentUser -Force -SkipPublisherCheck
} else {
Write-Host "posh-docker module is installed"
}
# check for psreadline module (optional)
if (-not (Get-Command "Set-PSReadlineKeyHandler" -errorAction SilentlyContinue)) {
Install-Module -Name PSReadLine -AllowPrerelease -Scope CurrentUser -Force -SkipPublisherCheck
}
# checking for powershell profile file and create it if needed
if (-not (Test-Path -Path $PROFILE )) {
New-Item -Type File -Path $PROFILE -Force
} else {
Write-Host "Powershell profile found."
$delProfile = Read-Host -Prompt 'Do you want to replace it? [Y/n]'
if ($delProfile -eq 'y' -or $delProfile -eq 'Y') {
Rename-Item -Path $PROFILE -NewName "$PROFILE.bak" -Force
}
}
# adding HonukaiAlt theme
Import-Module posh-git
Import-Module oh-my-posh
$ohMyPoshModulePath = (Get-Item (Get-Module -name oh-my-posh).Path).Directory.FullName
$themeFileName = "$ohMyPoshModulePath/Themes/HonokaiAlt.psm1"
Invoke-WebRequest -Uri $urlOfTheme -OutFile $themeFileName
# append profile information
Add-Content -Path $PROFILE -Value ""
Add-Content -Path $PROFILE -Value "Import-Module posh-git"
Add-Content -Path $PROFILE -Value "Import-Module oh-my-posh"
Add-Content -Path $PROFILE -Value "Import-Module posh-docker"
Add-Content -Path $PROFILE -Value "Set-PSReadlineKeyHandler -Key Tab -Function Complete"
Add-Content -Path $PROFILE -Value "Set-Theme HonokaiAlt"
Write-Host "Please restart your shell to see the changes"
. $PROFILE
Clear-Host