-
Notifications
You must be signed in to change notification settings - Fork 2
/
dot.ps1
50 lines (45 loc) · 1.55 KB
/
dot.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
#
# nullxception's Dotfiles install script
# usage:
# ./dot.ps1 <module-name>
#
param(
[Parameter(Mandatory = $True)]
[String] $Module
)
$ModuleData = ".install.ps1"
function Install-Mod($ModulePath) {
$ModuleName = Split-Path $ModulePath -Leaf
$ModuleRPath = Resolve-Path $ModulePath\$ModuleData -ErrorAction SilentlyContinue
if (![System.IO.File]::Exists($ModuleRPath)) {
Return "Module $ModuleName does not exists or has no $ModuleData"
}
. $ModuleRPath
if (Get-Command 'dot_preinstall' -errorAction SilentlyContinue) {
dot_preinstall
}
if (Get-Command 'dot_install' -errorAction SilentlyContinue) {
dot_install
}
else {
Write-Output "installing module $ModuleName to $Installtarget"
if (![System.IO.Directory]::Exists($Installtarget)) {
New-Item -ItemType Directory -Path $Installtarget
}
Get-ChildItem -Path $ModulePath -Exclude $ModuleData,.install,README.md | Copy-Item -Destination $Installtarget -Recurse -Force
}
if (Get-Command 'dot_postinstall' -errorAction SilentlyContinue) {
dot_postinstall
}
# Unregister modules functions
if (Get-Command 'dot_preinstall' -errorAction SilentlyContinue) {
Remove-Item -Path Function:\dot_preinstall
}
if (Get-Command 'dot_install' -errorAction SilentlyContinue) {
Remove-Item -Path Function:\dot_install
}
if (Get-Command 'dot_postinstall' -errorAction SilentlyContinue) {
Remove-Item -Path Function:\dot_postinstall
}
}
Install-Mod $Module