From b58bcb5f81ae87d5f735cd3ea2ebcd6b705f6ba5 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn <github@nathan.woodburn.au> Date: Fri, 28 Mar 2025 16:21:29 +1100 Subject: [PATCH] fix: Try new dotfiles importer --- dotfiles.sh | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/dotfiles.sh b/dotfiles.sh index 5029119..0e87400 100755 --- a/dotfiles.sh +++ b/dotfiles.sh @@ -1,9 +1,12 @@ +#!/bin/bash + cd ~/.dotfiles git pull echo "Creating symbolic links for dotfiles..." -dirs_to_sym = (".config/alacritty/themes" ".zsh_functions") -sub_modules = (".config/alacritty/themes") +dirs_to_sym=(".config/alacritty/themes" ".zsh_functions") +sub_modules=(".config/alacritty/themes") +ignore_files=("README.md" ".git" ".gitmodules") # Function to create symlinks recursively create_symlinks() { @@ -12,23 +15,38 @@ create_symlinks() { # Create the target directory if it doesn't exist mkdir -p "$target_dir" + # For each file for file in "$src_dir"/*; do # Get the file name local file_name=$(basename "$file") + + # Check if file should be ignored + if [[ " ${ignore_files[@]} " =~ " $file_name " ]]; then + echo "Ignoring: $file_name" + continue + fi + # If the file is a directory if [ -d "$file" ]; then # Check if the directory is in the list of directories to symlink if [[ " ${dirs_to_sym[@]} " =~ " $file_name " ]]; then - # If the directory is in the list, create a symlink - echo "Linking directory: $file -> $target_dir/$file_name" - ln -s "$file" "$target_dir/$file_name" + # For these special directories, create the directory and symlink contents + mkdir -p "$target_dir/$file_name" + # If this directory is also a submodule, initialize it + if [[ " ${sub_modules[@]} " =~ " $file_name " ]]; then + echo "Initializing submodule: $file_name" + (cd "$file" && git submodule update --init --recursive) + fi + # Recursively create symlinks for the contents + create_symlinks "$file" "$target_dir/$file_name" else - # If the directory is not in the list, recursively call the function + # For regular directories, create them and recurse + mkdir -p "$target_dir/$file_name" create_symlinks "$file" "$target_dir/$file_name" fi else - # If the file is not a symlink + # If the file is not a symlink already if [ ! -L "$target_dir/$file_name" ]; then # If the file exists if [ -e "$target_dir/$file_name" ]; then @@ -41,22 +59,9 @@ create_symlinks() { ln -s "$file" "$target_dir/$file_name" fi fi - done - - # For each submodule - for submodule in "${sub_modules[@]}"; do - # cd into the submodule and git submodule update --init --recursive - cd "$src_dir/$submodule" - git submodule update --init --recursive - # cd back to the src_dir - cd "$src_dir" done - - } - - # Call the function to create symlinks from dotfiles to home create_symlinks "$HOME/.dotfiles" "$HOME"