Skip to content

Commit 456eebe

Browse files
committed
❗ *!: New version setup file - improve symbolic links (add function) to recursively link files
1 parent 0f744db commit 456eebe

File tree

1 file changed

+22
-38
lines changed

1 file changed

+22
-38
lines changed

Setup.ps1

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
<#PSScriptInfo
33
4-
.VERSION 1.0.3
4+
.VERSION 1.1.0
55
66
.GUID ccb5be4c-ea07-4c45-a5b4-6310df24e2bc
77
@@ -284,6 +284,23 @@ function Write-LockFile {
284284
}
285285
}
286286

287+
function New-SymbolicLinks {
288+
param (
289+
[string]$Source,
290+
[string]$Destination,
291+
[switch]$Recurse
292+
)
293+
294+
Get-ChildItem $Source -Recurse:$Recurse | Where-Object { !$_.PSIsContainer } | ForEach-Object {
295+
$destinationPath = $_.FullName -replace [regex]::Escape($Source), $Destination
296+
if (!(Test-Path (Split-Path $destinationPath))) {
297+
New-Item (Split-Path $destinationPath) -ItemType Directory -Force -ErrorAction SilentlyContinue | Out-Null
298+
}
299+
New-Item -ItemType SymbolicLink -Path $destinationPath -Target $($_.FullName) -Force -ErrorAction SilentlyContinue | Out-Null
300+
Write-ColorText "{Blue}[symlink] {Green}$($_.FullName) {Yellow}--> {Gray}$destinationPath"
301+
}
302+
}
303+
287304
########################################################################
288305
### MAIN SCRIPT ###
289306
########################################################################
@@ -602,42 +619,9 @@ if (Get-Command gh -ErrorAction SilentlyContinue) {
602619
####################################################################
603620
# symlinks
604621
Write-TitleBox -Title "Add symbolic links for dotfiles"
605-
$symlinks = @{
606-
$PROFILE.CurrentUserAllHosts = ".\Profile.ps1"
607-
"$Env:APPDATA\bat" = ".\config\bat"
608-
"$Env:APPDATA\Code\User\keybindings.json" = ".\vscode\keybindings.json"
609-
"$Env:APPDATA\Code\User\settings.json" = ".\vscode\settings.json"
610-
"$Env:LOCALAPPDATA\fastfetch" = ".\config\fastfetch"
611-
"$Env:LOCALAPPDATA\lazygit" = ".\config\lazygit"
612-
"$Env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json" = ".\windows\settings.json"
613-
"$HOME\.bash_profile" = ".\home\.bash_profile"
614-
"$HOME\.bashrc" = ".\home\.bashrc"
615-
"$HOME\.config\bash" = ".\config\bash"
616-
"$HOME\.config\delta" = ".\config\delta"
617-
"$HOME\.config\eza" = ".\config\eza"
618-
"$HOME\.config\gh-dash" = ".\config\gh-dash"
619-
"$HOME\.config\gitaliases" = ".\config\gitaliases"
620-
"$HOME\.config\komorebi" = ".\config\komorebi"
621-
"$HOME\.config\mise" = ".\config\mise"
622-
"$HOME\.config\spotify-tui" = ".\config\spotify-tui"
623-
"$HOME\.config\starship.toml" = ".\config\starship.toml"
624-
"$HOME\.config\whkdrc" = ".\config\whkdrc"
625-
"$HOME\.config\yasb" = ".\config\yasb"
626-
"$HOME\.config\yazi" = ".\config\yazi"
627-
"$HOME\.czrc" = ".\home\.czrc"
628-
"$HOME\.gitconfig" = ".\home\.gitconfig"
629-
"$HOME\.inputrc" = ".\home\.inputrc"
630-
"$HOME\.npmrc" = ".\home\.npmrc"
631-
"$HOME\.wslconfig" = ".\home\.wslconfig"
632-
}
633-
634-
# add symlinks
635-
foreach ($symlink in $symlinks.GetEnumerator()) {
636-
Write-Verbose -Message "Creating symlink for $(Resolve-Path $symlink.Value) --> $($symlink.Key)"
637-
Get-Item -Path $symlink.Key -ErrorAction SilentlyContinue | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue
638-
New-Item -ItemType SymbolicLink -Path $symlink.Key -Target (Resolve-Path $symlink.Value) -Force | Out-Null
639-
Write-ColorText "{Blue}[symlink] {Green}$(Resolve-Path $symlink.Value) {Yellow}--> {Gray}$($symlink.Key)"
640-
}
622+
New-SymbolicLinks -Source "$PSScriptRoot\config\home" -Destination "$env:USERPROFILE" -Recurse
623+
New-SymbolicLinks -Source "$PSScriptRoot\config\AppData" -Destination "$env:USERPROFILE\AppData" -Recurse
624+
New-SymbolicLinks -Source "$PSScriptRoot\config\config" -Destination "$env:USERPROFILE\.config" -Recurse
641625
Refresh ($i++)
642626

643627
# Set the right git name and email for the user after symlinking
@@ -745,7 +729,7 @@ Refresh ($i++)
745729
# VSCode Extensions
746730
if (Get-Command code -ErrorAction SilentlyContinue) {
747731
Write-TitleBox -Title "VSCode Extensions Installation"
748-
$extensionList = Get-Content "$PSScriptRoot\vscode\extensions.list"
732+
$extensionList = Get-Content "$PSScriptRoot\extensions.list"
749733
foreach ($ext in $extensionList) {
750734
if (!(code --list-extensions | Select-String "$ext")) {
751735
Write-Verbose -Message "Installing VSCode Extension: $ext"

0 commit comments

Comments
 (0)