-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.ps1
More file actions
59 lines (41 loc) · 1.77 KB
/
setup.ps1
File metadata and controls
59 lines (41 loc) · 1.77 KB
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
$files='.gitconfig', '.gvimrc', '.tigrc', '.tmux.conf', '.vimrc', '.zshrc', '.ghci'
# ----
function isSymboliLink($path) {
(Test-Path $path) -and ((Get-Item $path).Attributes.ToString() -match "Reparse")
}
function makeSymbolicLink($originalPath, $linkPathToCreate) {
& "$env:ComSpec" /c mklink $linkPathToCreate $originalPath
#New-Item -ItemType SymbolicLink -Path $linkPathToCreate -Value $originalPath
}
# ----
$targetDirectory = $HOME
Set-Location $PSScriptRoot
Write-Host "Configurations:"
Write-Host " Current Directory: $PWD.Path"
Write-Host " TargetDirectory: $targetDirectory"
Write-Host ""
Write-Host "# Make Symbolic Links"
Push-Location $targetDirectory
ForEach ($path in $files) {
$private:originDir = Get-Location -stack # => ~/dotfiles
$private:relativeDir = Resolve-Path -Relative $originDir # => ./dotfiles
$private:originalPath = Join-Path $relativeDir $path # => ./dotfiles/.gitconfig
$private:linkPathToCreate = $path # => .gitconfig
Write-Host " Make symbolic link: $originalPath -> $linkPathToCreate ..."
if (isSymboliLink($linkPathToCreate)) {
# Remove it if target path is a Symbolic Link.
Write-Host " Removing $linkPathToCreate ..."
Remove-Item $linkPathToCreate
} elseif (Test-Path $linkPathToCreate) {
# Keep existen file if target path is NOT a symlink.
Write-Host " Backup $linkPathToCreate -> $linkPathToCreate.bak"
Move-Item $linkPathToCreate "$linkPathToCreate.bak"
}
makeSymbolicLink $originalPath $linkPathToCreate
Write-Host ""
}
Pop-Location
# Show target files
#$files | % { Join-Path $targetDirectory $_ } | ls
& "$env:ComSpec" /c "dir $targetDirectory | findStr SYMLINK"
pause