From 12bea8b3f8d8910fd373fbc1317e0a951e263b79 Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Mon, 11 May 2026 21:01:19 +0545 Subject: [PATCH] feat(root): add install script for dotfile symlinkingThis script automates the setup of dotfiles by symlinking configuration folders, the Zsh configuration file, and scripts to the appropriate user directories, with backup handling for existing files. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New Features- Added `install.sh` to symlink configs, `.zshrc`, and scripts. - Creates `~/.config` and `~/.local/bin` directories if missing. - Backs up existing files before replacement. Enhancements- Provides clear step‑by‑step progress messages. Bug Fixes - None. --- install.sh | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100755 install.sh diff --git a/install.sh b/install.sh new file mode 100755 index 00000000..6f738483 --- /dev/null +++ b/install.sh @@ -0,0 +1,85 @@ +#!/bin/bash + +# This script sets up the dotfiles by symlinking the config folders +# and sourcing the zsh configuration. + +# Get the absolute path of the project directory +PROJECT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +CONFIG_SRC_DIR="$PROJECT_DIR/config" +ZSHRC_SRC="$PROJECT_DIR/misc/.zshrc" + +# Target directory for configs +CONFIG_DEST_DIR="$HOME/.config" + +# Create ~/.config if it doesn't exist +mkdir -p "$CONFIG_DEST_DIR" + +echo "Step 1: Symlinking configuration folders to $CONFIG_DEST_DIR..." + +# Loop through all folders and files in the project's config directory +for item in "$CONFIG_SRC_DIR"/*; do + if [ -e "$item" ]; then + name=$(basename "$item") + + # Skip the 'archive' directory + if [ "$name" == "archive" ]; then + continue + fi + + target="$CONFIG_DEST_DIR/$name" + + # Check if target exists and is not a symlink + if [ -e "$target" ] && [ ! -L "$target" ]; then + echo " [WARN] $name already exists as a real directory/file. Backing up to ${name}.bak" + mv "$target" "${target}.bak" + fi + + # -s: symbolic link + # -n: treat destination that is a symlink to a directory as a normal file + # -f: force (remove existing destination) + ln -snf "$item" "$target" + echo " [OK] Linked $name" + fi +done + +echo "Step 2: Symlinking misc/.zshrc to $HOME/.zshrc..." + +ZSHRC_DEST="$HOME/.zshrc" + +# Check if target exists and is not a symlink +if [ -e "$ZSHRC_DEST" ] && [ ! -L "$ZSHRC_DEST" ]; then + echo " [WARN] .zshrc already exists. Backing up to .zshrc.bak" + mv "$ZSHRC_DEST" "${ZSHRC_DEST}.bak" +fi + +ln -snf "$ZSHRC_SRC" "$ZSHRC_DEST" +echo " [OK] Linked .zshrc" + +echo "Step 3: Symlinking scripts from misc/bin to $HOME/.local/bin..." + +BIN_SRC_DIR="$PROJECT_DIR/misc/bin" +BIN_DEST_DIR="$HOME/.local/bin" + +mkdir -p "$BIN_DEST_DIR" + +for item in "$BIN_SRC_DIR"/*; do + if [ -e "$item" ]; then + name=$(basename "$item") + target="$BIN_DEST_DIR/$name" + + # Check if target exists and is not a symlink + if [ -e "$target" ] && [ ! -L "$target" ]; then + echo " [WARN] $name already exists in ~/.local/bin. Backing up to ${name}.bak" + mv "$target" "${target}.bak" + fi + + # Ensure the script is executable + chmod +x "$item" + + ln -snf "$item" "$target" + echo " [OK] Linked $name" + fi +done + +echo "" +echo "All done! Please restart your terminal or run 'source ~/.zshrc'."