-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-i3.sh
53 lines (46 loc) · 1.23 KB
/
setup-i3.sh
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
#!/bin/bash
# Define the dotfiles directory and backup directory
DOTFILES_DIR="$HOME/dotfiles"
BACKUP_DIR="$HOME/dotfiles_backup_$(date +%Y%m%d_%H%M%S)"
# Create backup directory
mkdir -p "$BACKUP_DIR"
# Function to backup and remove existing dotfiles
backup_and_remove() {
local file="$1"
if [ -e "$HOME/$file" ]; then
mv "$HOME/$file" "$BACKUP_DIR/"
echo "Backed up and removed: $file"
fi
}
# List of folders to ignore (add or remove as needed)
ignore_folders=(
"scripts"
"arconet-qtile"
"templates"
"docs"
# Add more folders to ignore here
)
# Convert ignore_folders array to a string for use with grep
ignore_pattern=$(
IFS="|"
echo "${ignore_folders[*]}"
)
# Backup and remove existing dotfiles
cd "$DOTFILES_DIR"
for dir in */; do
dir=${dir%/} # Remove trailing slash
if ! echo "$dir" | grep -qE "^($ignore_pattern)$"; then
for file in "$dir"/*; do
if [ -f "$file" ]; then
relative_path="${file#./}"
backup_and_remove "$relative_path"
fi
done
# Stow each directory individually
stow "$dir"
echo "Stowed $dir"
else
echo "Ignored $dir"
fi
done
echo "Dotfiles have been backed up to $BACKUP_DIR and new symlinks created with Stow, excluding specified folders."