From b31334a1c1b2a80627d698c8121f625bef573679 Mon Sep 17 00:00:00 2001
From: Nathan Woodburn <github@nathan.woodburn.au>
Date: Fri, 28 Mar 2025 16:17:38 +1100
Subject: [PATCH] feat: Update dotfiles

---
 dotfiles.sh | 102 ++++++++++++++++++++++------------------------------
 setup.sh    |   8 ++---
 2 files changed, 47 insertions(+), 63 deletions(-)

diff --git a/dotfiles.sh b/dotfiles.sh
index 2775448..5029119 100755
--- a/dotfiles.sh
+++ b/dotfiles.sh
@@ -2,71 +2,55 @@ cd ~/.dotfiles
 git pull
 echo "Creating symbolic links for dotfiles..."
 
+dirs_to_sym = (".config/alacritty/themes" ".zsh_functions")
+sub_modules = (".config/alacritty/themes")
+
 # Function to create symlinks recursively
 create_symlinks() {
-  local src_dir="$1"
-  local target_dir="$2"
-  
-  # Create the target directory if it doesn't exist
-  mkdir -p "$target_dir"
-  
-  # Handle .zsh_functions directory specially - link the whole directory
-  if [ -d "$src_dir/.zsh_functions" ]; then
-    local target_zsh_functions="$target_dir/.zsh_functions"
-    
-    # Remove existing directory or symlink if it exists
-    if [ -e "$target_zsh_functions" ] || [ -L "$target_zsh_functions" ]; then
-      echo "Removing existing: $target_zsh_functions"
-      rm -rf "$target_zsh_functions"
-    fi
-    
-    # Create symlink for the entire directory
-    echo "Linking directory: $src_dir/.zsh_functions -> $target_zsh_functions"
-    ln -s "$src_dir/.zsh_functions" "$target_zsh_functions"
-  fi
+    local src_dir="$1"
+    local target_dir="$2"
 
-  # Find all files and directories in the source directory, excluding .git, README.md, and .zsh_functions
-  find "$src_dir" \( -not -path "*/\.git*" -and -not -name "README.md" -and -not -path "*/.zsh_functions/*" -and -not -path "*/.zsh_functions" \) -and \( -type f -o -type l \) | while read -r src_file; do
-    # Get the relative path from src_dir
-    rel_path="${src_file#$src_dir/}"
-    
-    # Construct the target file path
-    target_file="$target_dir/$rel_path"
-    
-    # Create parent directories if they don't exist
-    mkdir -p "$(dirname "$target_file")"
-    
-    # Remove existing file if it exists
-    if [ -e "$target_file" ] || [ -L "$target_file" ]; then
-      echo "Removing existing file: $target_file"
-      rm -f "$target_file"
-    fi
-    
-    # Create symlink
-    echo "Linking: $src_file -> $target_file"
-    ln -s "$src_file" "$target_file"
-  done
-
-     # Handle .config/alacritty/themes directory specially - link the whole directory
-    if [ -d "$src_dir/.config/alacritty/themes" ]; then
-        local target_alacritty_themes="$target_dir/.config/alacritty/themes"
-        
-        # Remove existing directory or symlink if it exists
-        if [ -e "$target_alacritty_themes" ] || [ -L "$target_alacritty_themes" ]; then
-        echo "Removing existing: $target_alacritty_themes"
-        rm -rf "$target_alacritty_themes"
+    # 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")
+        # 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"
+            else
+                # If the directory is not in the list, recursively call the function
+                create_symlinks "$file" "$target_dir/$file_name"
+            fi
+        else
+            # If the file is not a symlink
+            if [ ! -L "$target_dir/$file_name" ]; then
+                # If the file exists
+                if [ -e "$target_dir/$file_name" ]; then
+                    # Remove the file
+                    echo "Removing existing: $target_dir/$file_name"
+                    rm -rf "$target_dir/$file_name"
+                fi
+                # Create a symlink
+                echo "Linking: $file -> $target_dir/$file_name"
+                ln -s "$file" "$target_dir/$file_name"
+            fi
         fi
-        
-        # Ensure .config/alacritty directory exists
-        mkdir -p "$target_dir/.config/alacritty"
+    done    
 
-        # Make sure to pull latest changes from the repo submodules
+    # 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
-
-        # Create symlink for the entire directory
-        echo "Linking directory: $src_dir/.config/alacritty/themes -> $target_alacritty_themes"
-        ln -s "$src_dir/.config/alacritty/themes" "$target_alacritty_themes"
-    fi
+        # cd back to the src_dir
+        cd "$src_dir"
+    done
 
 
 }
diff --git a/setup.sh b/setup.sh
index b917bcb..8278921 100755
--- a/setup.sh
+++ b/setup.sh
@@ -3,8 +3,8 @@
 # Install dependencies
 sudo apt-get update
 
-# Python 3 and related packages
-sudo apt-get install -y python3 python3-pip python3-venv curl wget
+# Python 3 and dependencies
+sudo apt-get install -y python3 python3-pip python3-venv curl wget unzip
 
 # Install most stuff
 sudo apt-get install -y zsh bat fzf jq knot-dnsutils tre-command polybar
@@ -25,7 +25,7 @@ curl --proto '=https' --tlsv1.2 -LsSf https://setup.atuin.sh | sh
 cargo install eza
 
 # Install Alacritty
-sudo apt install cmake g++ pkg-config libfreetype6-dev libfontconfig1-dev libxcb-xfixes0-dev libxkbcommon-dev
+sudo apt install -y cmake g++ pkg-config libfreetype6-dev libfontconfig1-dev libxcb-xfixes0-dev libxkbcommon-dev
 cargo install alacritty
 # Add to menu
 sudo cp ./alacritty-term.svg /usr/share/pixmaps/Alacritty.svg
@@ -42,4 +42,4 @@ git clone git@woodburn.au:nathanwoodburn/dotfiles.git ~/.dotfiles
 git clone git@woodburn.au:nathanwoodburn/scripts.git ~/scripts
 
 # Install fonts
-sudo apt install fonts-firacode
\ No newline at end of file
+sudo apt install -y fonts-firacode
\ No newline at end of file