-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.ps1
61 lines (56 loc) · 2.05 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
param([switch]$Development = $true)
if($Development) {
$posh = Get-Module 'posh-git';
if(-not $posh) {
Write-Host "Installing Module: 'posh-git'";
Install-Module posh-git -Scope CurrentUser;
}
if($IsLinux -or $IsMacOS) {
$modules = [IO.DirectoryInfo]"$HOME/.local/share/powershell/Modules";
} else {
$docs = [Environment]::GetFolderPath("mydocuments");
if ($PSEdition -eq 'Core') {
$modules = [IO.DirectoryInfo]"$docs\PowerShell\Modules";
} else {
$modules = [IO.DirectoryInfo]"$docs\WindowsPowerShell\Modules";
}
}
if(-not $modules.Exists) {
[IO.Directory]::CreateDirectory($modules.FullName);
}
# Create link
if(-not [IO.Directory]::Exists($link)) {
if($IsLinux -Or $IsMacOS) {
$link = "$modules/Powerd";
$target = "$PSScriptRoot/Modules/Powerd";
Write-Host "Linking $target to $link";
ln -sd $target $link;
} else {
$link = "$modules\Powerd";
$target = "$PSScriptRoot\Modules\Powerd";
Write-Host "Linking $target to $link";
New-Item -ItemType SymbolicLink -Path $link -Target $target;
}
if($LASTEXITCODE -ne 0) {
throw "Error linking $target to $link";
}
}
$profileFile = [IO.FileInfo]$profile;
if(-not $profileFile.Exists) {
if(-not $profileFile.Directory.Exists) {
[IO.Directory]::CreateDirectory($profileFile.Directory.FullName);
}
Set-Content $profileFile -Value "";
}
$existing = Get-Content $profileFile;
if(-not ($existing -like '*posh-git*')) {
Write-Host "Adding 'Import-Module posh-git;' to your PowerShell Profile";
Add-Content -Value "Import-Module posh-git;" -Path $profileFile;
}
if(-not ($existing -like '*Powerd*')) {
Write-Host "Adding 'Import-Module Powerd;' to your PowerShell Profile";
Add-Content -Value "Import-Module Powerd;" -Path $profileFile;
}
} else {
throw "Not implemented";
}