fix: Add some more logic
This commit is contained in:
parent
2d6275f465
commit
645b49d313
49
dotfiles.sh
49
dotfiles.sh
@ -4,6 +4,7 @@ cd ~/.dotfiles
|
|||||||
git pull
|
git pull
|
||||||
echo "Creating symbolic links for dotfiles..."
|
echo "Creating symbolic links for dotfiles..."
|
||||||
|
|
||||||
|
# Convert paths to array of directory names to special handle
|
||||||
dirs_to_sym=(".config/alacritty/themes" ".zsh_functions")
|
dirs_to_sym=(".config/alacritty/themes" ".zsh_functions")
|
||||||
sub_modules=(".config/alacritty/themes")
|
sub_modules=(".config/alacritty/themes")
|
||||||
ignore_files=("README.md" ".git" ".gitmodules")
|
ignore_files=("README.md" ".git" ".gitmodules")
|
||||||
@ -12,6 +13,8 @@ ignore_files=("README.md" ".git" ".gitmodules")
|
|||||||
create_symlinks() {
|
create_symlinks() {
|
||||||
local src_dir="$1"
|
local src_dir="$1"
|
||||||
local target_dir="$2"
|
local target_dir="$2"
|
||||||
|
local is_root="$3" # Flag to indicate if this is the root call
|
||||||
|
|
||||||
# Create the target directory if it doesn't exist
|
# Create the target directory if it doesn't exist
|
||||||
mkdir -p "$target_dir"
|
mkdir -p "$target_dir"
|
||||||
|
|
||||||
@ -21,9 +24,9 @@ create_symlinks() {
|
|||||||
# Skip if the file doesn't exist (can happen if no hidden files)
|
# Skip if the file doesn't exist (can happen if no hidden files)
|
||||||
[ -e "$file" ] || continue
|
[ -e "$file" ] || continue
|
||||||
|
|
||||||
echo "Processing: $file"
|
|
||||||
# Get the file name
|
# Get the file name
|
||||||
local file_name=$(basename "$file")
|
local file_name=$(basename "$file")
|
||||||
|
local rel_path=${file#$HOME/.dotfiles/} # Get relative path
|
||||||
|
|
||||||
# Check if file should be ignored
|
# Check if file should be ignored
|
||||||
if [[ " ${ignore_files[@]} " =~ " $file_name " ]]; then
|
if [[ " ${ignore_files[@]} " =~ " $file_name " ]]; then
|
||||||
@ -33,33 +36,43 @@ create_symlinks() {
|
|||||||
|
|
||||||
# If the file is a directory
|
# If the file is a directory
|
||||||
if [ -d "$file" ]; then
|
if [ -d "$file" ]; then
|
||||||
# Check if the directory is in the list of directories to symlink
|
# Handle directory symlinking based on whether it's in the special directories list
|
||||||
if [[ " ${dirs_to_sym[@]} " =~ " $file_name " ]]; then
|
if [[ "$is_root" == "true" && "$file_name" == ".config" ]]; then
|
||||||
# For these special directories, create the directory and symlink contents
|
# For .config directory, we want to create it and process its contents differently
|
||||||
|
mkdir -p "$target_dir/.config"
|
||||||
|
create_symlinks "$file" "$target_dir/.config" "false"
|
||||||
|
elif [[ " ${dirs_to_sym[@]} " =~ " $rel_path " ]]; then
|
||||||
|
# Special directory that needs special handling
|
||||||
|
echo "Special directory: $rel_path"
|
||||||
mkdir -p "$target_dir/$file_name"
|
mkdir -p "$target_dir/$file_name"
|
||||||
# If this directory is also a submodule, initialize it
|
|
||||||
if [[ " ${sub_modules[@]} " =~ " $file_name " ]]; then
|
# Handle submodule initialization if needed
|
||||||
echo "Initializing submodule: $file_name"
|
if [[ " ${sub_modules[@]} " =~ " $rel_path " ]]; then
|
||||||
|
echo "Initializing submodule: $rel_path"
|
||||||
(cd "$file" && git submodule update --init --recursive)
|
(cd "$file" && git submodule update --init --recursive)
|
||||||
fi
|
fi
|
||||||
# Recursively create symlinks for the contents
|
|
||||||
create_symlinks "$file" "$target_dir/$file_name"
|
# Process the contents
|
||||||
|
create_symlinks "$file" "$target_dir/$file_name" "false"
|
||||||
else
|
else
|
||||||
# For regular directories, create them and recurse
|
# For regular directories in our dotfiles, we want to symlink them directly
|
||||||
mkdir -p "$target_dir/$file_name"
|
if [ ! -L "$target_dir/$file_name" ]; then
|
||||||
create_symlinks "$file" "$target_dir/$file_name"
|
if [ -e "$target_dir/$file_name" ]; then
|
||||||
|
echo "Removing existing: $target_dir/$file_name"
|
||||||
|
rm -rf "$target_dir/$file_name"
|
||||||
|
fi
|
||||||
|
echo "Linking directory: $file -> $target_dir/$file_name"
|
||||||
|
ln -s "$file" "$target_dir/$file_name"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# If the file is not a symlink already
|
# For regular files, always create symlinks
|
||||||
if [ ! -L "$target_dir/$file_name" ]; then
|
if [ ! -L "$target_dir/$file_name" ]; then
|
||||||
# If the file exists
|
|
||||||
if [ -e "$target_dir/$file_name" ]; then
|
if [ -e "$target_dir/$file_name" ]; then
|
||||||
# Remove the file
|
|
||||||
echo "Removing existing: $target_dir/$file_name"
|
echo "Removing existing: $target_dir/$file_name"
|
||||||
rm -rf "$target_dir/$file_name"
|
rm -rf "$target_dir/$file_name"
|
||||||
fi
|
fi
|
||||||
# Create a symlink
|
echo "Linking file: $file -> $target_dir/$file_name"
|
||||||
echo "Linking: $file -> $target_dir/$file_name"
|
|
||||||
ln -s "$file" "$target_dir/$file_name"
|
ln -s "$file" "$target_dir/$file_name"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@ -67,6 +80,6 @@ create_symlinks() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# Call the function to create symlinks from dotfiles to home
|
# Call the function to create symlinks from dotfiles to home
|
||||||
create_symlinks "$HOME/.dotfiles" "$HOME"
|
create_symlinks "$HOME/.dotfiles" "$HOME" "true"
|
||||||
|
|
||||||
echo "Dotfiles setup complete!"
|
echo "Dotfiles setup complete!"
|
Loading…
Reference in New Issue
Block a user