-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.ps1
59 lines (51 loc) · 1.75 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
$scriptPath = $MyInvocation.MyCommand.Path
$dotfilePath = Split-Path $scriptPath
$installAll = $false
function CanInstall([string] $path) {
if ((!$installAll) -and (Test-Path $path)) {
$key = Read-Host "Dotfile $destination already exists. Overwrite it? [Y/n/a]"
if ($key -eq "n") {
return $false
}
if ($key -eq "a") {
$script:installAll = $true
}
}
return $true
}
function InstallDotFile([string] $source, [string] $destination) {
if (CanInstall $destination) {
Write-Host "Install dotfile $destination"
if (Test-Path $destination) {
Remove-Item $destination -Recurse
}
Copy-Item $source $destination -Recurse
}
}
function InstallDotFilesIn([string] $path) {
$sourcePath = $dotfilePath + '\' + $path;
foreach($file in Get-ChildItem -Exclude "vim" $sourcePath -Name) {
InstallDotFile "$sourcePath\$file" "$HOME\.$file"
}
}
function CreatePowerShellProfile {
$psprofilePath = "$dotfilePath\powershell\profile.ps1"
$dotProfile = ". $psprofilePath"
if (!(Test-Path $PROFILE)) {
New-Item -ItemType File -Path $PROFILE
}
$oldContent = Get-Content $PROFILE
if (($oldContent -eq $null) -or !$oldContent.Contains($dotProfile)) {
Set-Content -Path $PROFILE -Value "#"
Add-Content -Path $PROFILE -Value "# Source profile.ps1 from dotfiles"
Add-Content -Path $PROFILE -Value "#"
Add-Content -Path $PROFILE -Value $dotProfile
Add-Content -Path $PROFILE -Value ""
Add-Content -Path $PROFILE -value $oldContent
}
}
InstallDotFilesIn "independent"
InstallDotFilesIn "bash"
InstallDotFile "$dotfilePath\independent\vim" "$HOME\vimfiles"
CreatePowerShellProfile
InstallDotFile "$dotfilePath\gitignores" "$HOME\.gitignores"