-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
60 lines (47 loc) · 1.79 KB
/
setup.sh
File metadata and controls
60 lines (47 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/bash
# Stop on first error
set -e
DOTFILES_DIR="$HOME/dotfiles"
BACKUP_DIR="$HOME/.dotfiles_backup"
# key = path within the dotfiles repo | value = path in the home directory
declare -A SYMLINK_MAP=(
["bash/.bashrc"]=".bashrc"
["starship/starship.toml"]=".config/starship.toml"
["code/settings.json"]=".config/Code/User/settings.json"
["code/keybindings.json"]=".config/Code/User/keybindings.json"
["code/launch.json"]=".config/Code/User/launch.json"
)
echo "🚀 Starting dotfiles setup..."
if [ ! -d "$DOTFILES_DIR" ]; then
echo "Error: Dotfiles directory not found at $DOTFILES_DIR."
echo "Please clone the repository first: git clone <your-repo-url> $DOTFILES_DIR"
exit 1
fi
echo "Creating backup directory at $BACKUP_DIR..."
mkdir -p "$BACKUP_DIR"
# Iterate over the map to create symlinks
for src in "${!SYMLINK_MAP[@]}"; do
dest="${SYMLINK_MAP[$src]}"
SOURCE_FILE="$DOTFILES_DIR/$src"
DEST_FILE="$HOME/$dest"
# Check if the source file actually exists
if [ ! -f "$SOURCE_FILE" ]; then
echo "⚠️ Warning: Source file not found, skipping: $SOURCE_FILE"
continue
fi
# If the destination file already exists, back it up
if [ -e "$DEST_FILE" ] || [ -L "$DEST_FILE" ]; then
echo "Backing up existing file: $DEST_FILE"
# Create the destination's parent directory in the backup folder if needed
mkdir -p "$(dirname "$BACKUP_DIR/$dest")"
mv "$DEST_FILE" "$BACKUP_DIR/$dest"
fi
# Create the parent directory for the destination if it doesn't exist
# (e.g., for ~/.config/hypr/)
mkdir -p "$(dirname "$DEST_FILE")"
# Create the symlink
echo "🔗 Linking $SOURCE_FILE -> $DEST_FILE"
ln -s "$SOURCE_FILE" "$DEST_FILE"
done
echo "✅ Dotfiles setup complete!"
echo "👉 Please restart your shell or run 'source ~/.bashrc' to apply changes."