dotfiles/manage_configs.sh
sam rolfe e35b894b5d dotfiles for terminals
Dotfiles plugins etc to create sym links for ubuntu to access required
settings etc from gitea.
2025-10-06 16:08:40 +11:00

77 lines
2.1 KiB
Bash
Executable File

#!/bin/bash
# A script to back up, move, and symlink configuration files/directories
# from ~/.config to the dotfiles repository.
# --- Configuration ---
# Source directory for configs
CONFIG_DIR="$HOME/.config"
# Destination directory within the dotfiles repo
DOTFILES_DIR="$HOME/dotfiles"
# List of DIRECTORIES to manage
DIRS_TO_MANAGE=(
"atuin"
"borg"
"btop"
"carapace"
"gh"
"ghostty"
"kitty"
"lazygit"
"nushell"
"zellij"
)
# List of FILES to manage
FILES_TO_MANAGE=(
"starship.toml"
)
# --- End of Configuration ---
# Ensure the target directory for configs exists in the dotfiles repo
mkdir -p "$DOTFILES_DIR/.config"
TARGET_DIR="$DOTFILES_DIR/.config"
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
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"
echo " - Moving to $TARGET_DIR"
mv "$SOURCE_PATH" "$TARGET_DIR/"
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."