-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackup.sh
More file actions
executable file
·71 lines (57 loc) · 2.02 KB
/
backup.sh
File metadata and controls
executable file
·71 lines (57 loc) · 2.02 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
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env bash
# Exit immediately if a command exits with a non-zero status.
set -e
echo "Starting config backup..."
# Get the absolute path to the directory where this script is located (the repo root)
REPO_ROOT=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &>/dev/null && pwd)
echo "Repo root found at: $REPO_ROOT"
echo "Copying local configs into repo..."
# --- ghostty ---
# Ensure the target directory exists
mkdir -p "$REPO_ROOT/ghostty"
# Copy the file
cp -f ~/.config/ghostty/config.ghostty "$REPO_ROOT/ghostty/config.ghostty"
echo "Backed up config.ghostty"
# --- tmux ---
# Ensure the target directory exists
mkdir -p "$REPO_ROOT/tmux"
# Copy the file
cp -f ~/.tmux.conf "$REPO_ROOT/tmux/tmux.conf"
echo "Backed up tmux.conf"
# --- gitmux ---
# Ensure the target directory exists
mkdir -p "$REPO_ROOT/gitmux"
# Copy the file
cp -f ~/.gitmux.conf "$REPO_ROOT/gitmux/gitmux.conf"
echo "Backed up gitmux.conf"
# --- Starship ---
# Ensure the target directory exists
mkdir -p "$REPO_ROOT/starship"
# Copy the file
cp -f ~/.config/starship.toml "$REPO_ROOT/starship/starship.toml"
echo "Backed up starship.toml"
# --- nvim ---
# Ensure the target directory exists
mkdir -p "$REPO_ROOT/nvim"
# Use rsync to sync the contents of your nvim config into the repo's nvim dir
# -a: archive mode (recursive, preserves permissions, etc.)
# --delete: deletes files in the repo's nvim/ dir that are NO longer in your local ~/.config/nvim/
echo "Syncing nvim configs..."
rsync -a --delete ~/.config/nvim/ "$REPO_ROOT/nvim/"
echo "Nvim sync complete."
echo "Files copied. Committing to git..."
# Navigate to the repo directory to run git commands
cd "$REPO_ROOT"
# Check if there are any changes to commit
if [[ -z $(git status --porcelain) ]]; then
echo "No changes detected. Backup complete."
exit 0
fi
# Get metadata for commit message
date_time=$(date "+%Y-%m-%d at %H:%M:%S")
device_name=$(hostname)
# Add, commit, and push
git add .
git commit -m "Config backup on $date_time from $device_name"
git push
echo "Backup complete and pushed to remote!"