From 5e865e144e14e9618afc705397f4c8b40c8364f5 Mon Sep 17 00:00:00 2001 From: sam rolfe Date: Mon, 6 Oct 2025 19:36:57 +1100 Subject: [PATCH] fix manage configs .sh --- fix_links.sh | 45 --------------------- manage_configs.sh | 95 +++++++++++++++------------------------------ nushell/history.txt | 3 ++ 3 files changed, 35 insertions(+), 108 deletions(-) delete mode 100755 fix_links.sh diff --git a/fix_links.sh b/fix_links.sh deleted file mode 100755 index 379d5b8..0000000 --- a/fix_links.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash - -# A script to REMOVE old broken links and CREATE correct new ones. - -DOTFILES_DIR="$HOME/dotfiles" -CONFIG_DIR="$HOME/.config" - -# List of all config DIRECTORIES to be linked into ~/.config -CONFIG_DIRS=( - "atuin" "borg" "btop" "carapace" "gh" "ghostty" - "kitty" "lazygit" "nushell" "nvim" "zellij" -) - -echo "--- Starting to fix symbolic links ---" - -# --- 1. Fix links for directories inside ~/.config --- -for dir in "${CONFIG_DIRS[@]}"; do - SOURCE_PATH="$DOTFILES_DIR/$dir" - LINK_PATH="$CONFIG_DIR/$dir" - - echo "-> Processing $dir..." - # Remove any existing file or broken link at the destination - rm -rf "$LINK_PATH" - # Create the new, correct symlink - ln -s "$SOURCE_PATH" "$LINK_PATH" - echo " Linked $SOURCE_PATH -> $LINK_PATH" -done - -# --- 2. Fix link for starship.toml file in ~/.config --- -SOURCE_PATH_STARSHIP="$DOTFILES_DIR/starship.toml" -LINK_PATH_STARSHIP="$CONFIG_DIR/starship.toml" -echo "-> Processing starship.toml..." -rm -f "$LINK_PATH_STARSHIP" -ln -s "$SOURCE_PATH_STARSHIP" "$LINK_PATH_STARSHIP" -echo " Linked $SOURCE_PATH_STARSHIP -> $LINK_PATH_STARSHIP" - -# --- 3. Fix link for .zshrc file in ~ --- -SOURCE_PATH_ZSHRC="$DOTFILES_DIR/.zshrc" -LINK_PATH_ZSHRC="$HOME/.zshrc" -echo "-> Processing .zshrc..." -rm -f "$LINK_PATH_ZSHRC" -ln -s "$SOURCE_PATH_ZSHRC" "$LINK_PATH_ZSHRC" -echo " Linked $SOURCE_PATH_ZSHRC -> $LINK_PATH_ZSHRC" - -echo "--- All links have been reset correctly. ---" diff --git a/manage_configs.sh b/manage_configs.sh index 2c71878..379d5b8 100755 --- a/manage_configs.sh +++ b/manage_configs.sh @@ -1,76 +1,45 @@ #!/bin/bash -# A script to back up, move, and symlink configuration files/directories -# from ~/.config to the dotfiles repository. +# A script to REMOVE old broken links and CREATE correct new ones. -# --- Configuration --- -# Source directory for configs -CONFIG_DIR="$HOME/.config" -# Destination directory within the dotfiles repo DOTFILES_DIR="$HOME/dotfiles" +CONFIG_DIR="$HOME/.config" -# List of DIRECTORIES to manage -DIRS_TO_MANAGE=( - "atuin" - "borg" - "btop" - "carapace" - "gh" - "ghostty" - "kitty" - "lazygit" - "nushell" - "zellij" +# List of all config DIRECTORIES to be linked into ~/.config +CONFIG_DIRS=( + "atuin" "borg" "btop" "carapace" "gh" "ghostty" + "kitty" "lazygit" "nushell" "nvim" "zellij" ) -# List of FILES to manage -FILES_TO_MANAGE=( - "starship.toml" -) -# --- End of Configuration --- +echo "--- Starting to fix symbolic links ---" -# Ensure the target directory for configs exists in the dotfiles repo -mkdir -p "$DOTFILES_DIR/.config" -TARGET_DIR="$DOTFILES_DIR/.config" +# --- 1. Fix links for directories inside ~/.config --- +for dir in "${CONFIG_DIRS[@]}"; do + SOURCE_PATH="$DOTFILES_DIR/$dir" + LINK_PATH="$CONFIG_DIR/$dir" -echo "Starting configuration management..." - -# --- Process Directories --- -for dir in "${DIRS_TO_MANAGE[@]}"; do - SOURCE_PATH="$CONFIG_DIR/$dir" - # Check if the source is a real directory and not already a symlink - if [ -d "$SOURCE_PATH" ] && [ ! -L "$SOURCE_PATH" ]; then - echo " -> Processing directory: $dir" - echo " - Backing up to ${SOURCE_PATH}.bak" - cp -r "$SOURCE_PATH" "$SOURCE_PATH.bak" - - echo " - Moving to $TARGET_DIR" - mv "$SOURCE_PATH" "$TARGET_DIR/" - - echo " - Creating symlink at $SOURCE_PATH" - ln -s "$TARGET_DIR/$dir" "$SOURCE_PATH" - else - echo " -> Skipping $dir (does not exist or is already a symlink)." - fi + echo "-> Processing $dir..." + # Remove any existing file or broken link at the destination + rm -rf "$LINK_PATH" + # Create the new, correct symlink + ln -s "$SOURCE_PATH" "$LINK_PATH" + echo " Linked $SOURCE_PATH -> $LINK_PATH" done -# --- Process Files --- -for file in "${FILES_TO_MANAGE[@]}"; do - SOURCE_PATH="$CONFIG_DIR/$file" - # Check if the source is a real file and not already a symlink - if [ -f "$SOURCE_PATH" ] && [ ! -L "$SOURCE_PATH" ]; then - echo " -> Processing file: $file" - echo " - Backing up to ${SOURCE_PATH}.bak" - cp "$SOURCE_PATH" "$SOURCE_PATH.bak" +# --- 2. Fix link for starship.toml file in ~/.config --- +SOURCE_PATH_STARSHIP="$DOTFILES_DIR/starship.toml" +LINK_PATH_STARSHIP="$CONFIG_DIR/starship.toml" +echo "-> Processing starship.toml..." +rm -f "$LINK_PATH_STARSHIP" +ln -s "$SOURCE_PATH_STARSHIP" "$LINK_PATH_STARSHIP" +echo " Linked $SOURCE_PATH_STARSHIP -> $LINK_PATH_STARSHIP" - echo " - Moving to $TARGET_DIR" - mv "$SOURCE_PATH" "$TARGET_DIR/" +# --- 3. Fix link for .zshrc file in ~ --- +SOURCE_PATH_ZSHRC="$DOTFILES_DIR/.zshrc" +LINK_PATH_ZSHRC="$HOME/.zshrc" +echo "-> Processing .zshrc..." +rm -f "$LINK_PATH_ZSHRC" +ln -s "$SOURCE_PATH_ZSHRC" "$LINK_PATH_ZSHRC" +echo " Linked $SOURCE_PATH_ZSHRC -> $LINK_PATH_ZSHRC" - echo " - Creating symlink at $SOURCE_PATH" - ln -s "$TARGET_DIR/$file" "$SOURCE_PATH" - else - echo " -> Skipping $file (does not exist or is already a symlink)." - fi -done - -echo "Process complete." +echo "--- All links have been reset correctly. ---" diff --git a/nushell/history.txt b/nushell/history.txt index 62974e6..121df2d 100644 --- a/nushell/history.txt +++ b/nushell/history.txt @@ -50,3 +50,6 @@ yazi ~/dotfiles rm ~/.config/nvim ~/dotfiles/fix_links.sh cd ~/dotfiles +lazygit +rm ~/dotfiles/manage_configs.sh +mv ~/dotfiles/fix_links.sh ~/dotfiles/manage_configs.sh