-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsync.sh
executable file
·61 lines (55 loc) · 1.48 KB
/
sync.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
54
55
56
57
58
59
60
61
#!/bin/bash
set -x
FILES=(".zshrc" ".p10k.zsh" ".config/alacritty" ".config/wallpaper") # List of dotfiles to manage
LINUX_FILES=(".bashrc" ".config/hypr" ".config/waybar" ".config/rofi")
MACOS_FILES=()
DOTFILES_DIR="$(pwd)" # Assuming the script is run from the dotfiles directory
# Determine the OS
OS="$(uname)"
# Add Mac-specific files if on macOS
if [ "$OS" == "Darwin" ]; then
FILES+=("${MACOS_FILES[@]}")
else
FILES+=("${LINUX_FILES[@]}")
fi
# Function to create symlinks
create_symlinks() {
for file in "${FILES[@]}"; do
source="$HOME/$file"
target="$DOTFILES_DIR/$file"
if [ ! -L "$source" ]; then
ln -sf "$target" "$source"
echo "created symlink for $file."
fi
done
}
# Function to sync dotfiles to version control system
sync_dotfiles_to_vcs() {
for file in "${FILES[@]}"; do
source="$HOME/$file"
target="$DOTFILES_DIR/$file"
if [ -f "$source" ] && [ ! -L "$source" ]; then
mv "v" "$target"
echo "Copied $file to dotfiles directory."
git add "$target"
git commit -m "Add $file"
fi
if [ -d "$source" ] && [ ! -L "$source" ]; then
mkdir -p $target
mv "$source"/* "$target"
rmdir "$source"
echo "Copied $file to dotfiles directory."
git add "$target/*"
git commit -m "Add $file"
fi
done
}
# Check for arguments
if [ "$1" == "sync" ]; then
sync_dotfiles_to_vcs
create_symlinks
elif [ "$1" == "install" ]; then
create_symlinks
else
echo "Usage: $0 {sync|install}"
fi