-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstall
More file actions
executable file
·104 lines (83 loc) · 2.75 KB
/
Copy pathinstall
File metadata and controls
executable file
·104 lines (83 loc) · 2.75 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/bin/bash
set -e
DRY_RUN=false
VERBOSE=false
usage() {
echo "Usage: $0 [-n] [-v]" >&2
echo " -n dry run, show actions without executing" >&2
echo " -v verbose output" >&2
}
while getopts ":nv" opt; do
case "$opt" in
n) DRY_RUN=true ;;
v) VERBOSE=true ;;
*) usage; exit 1 ;;
esac
done
shift $((OPTIND-1))
DOTFILES=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
log() {
[ "$VERBOSE" = true ] && echo "$@"
}
link_file() {
local src="$1" dest="$2"
local backup_base backup_path
if [ ! -e "$src" ]; then
echo "Error: source '$src' does not exist" >&2
exit 1
fi
mkdir -p "$(dirname "$dest")"
# If destination is already the expected symlink, leave it alone.
if [ -L "$dest" ] && [ "$(readlink "$dest")" = "$src" ]; then
log "Already linked: $dest -> $src"
return 0
fi
# Never delete user data. Move existing paths to a timestamped backup.
if [ -e "$dest" ] || [ -L "$dest" ]; then
backup_base="${dest}.backup.$(date +%Y%m%d%H%M%S)"
backup_path="$backup_base"
while [ -e "$backup_path" ] || [ -L "$backup_path" ]; do
backup_path="${backup_base}.$RANDOM"
done
log "Backing up existing $dest -> $backup_path"
if [ "$DRY_RUN" = false ]; then
mv "$dest" "$backup_path"
fi
fi
log "ln -s $src $dest"
if [ "$DRY_RUN" = false ]; then
ln -s "$src" "$dest" || { echo "Failed to link $src -> $dest" >&2; exit 1; }
if [ ! -L "$dest" ]; then
echo "Error: expected '$dest' to be a symlink after linking" >&2
exit 1
fi
if [ "$(readlink "$dest")" != "$src" ]; then
echo "Error: verification failed for '$dest'" >&2
echo "Expected: $src" >&2
echo "Actual: $(readlink "$dest")" >&2
exit 1
fi
echo "Verified: $dest -> $src"
else
echo "Would verify: $dest -> $src"
fi
}
# common directories
mkdir -p "$HOME/.local/bin" "$HOME/.config" "$HOME/Library/Application Support" 2>/dev/null || true
link_file "$DOTFILES/.zshrc" "$HOME/.zshrc"
link_file "$DOTFILES/tmux/tmux.conf" "$HOME/.tmux.conf"
link_file "$DOTFILES/nvim" "$HOME/.config/nvim"
link_file "$DOTFILES/wezterm" "$HOME/.config/wezterm"
link_file "$DOTFILES/ghostty" "$HOME/Library/Application Support/com.mitchellh.ghostty"
link_file "$DOTFILES/.gitignore" "$HOME/.gitignore"
P10K_DIR="$HOME/bin/.powerlevel10k"
if [ ! -d "$P10K_DIR" ]; then
log "Installing powerlevel10k"
if [ "$DRY_RUN" = false ]; then
mkdir -p "$HOME/bin"
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git "$P10K_DIR"
fi
else
log "powerlevel10k already installed"
fi
echo "Install complete."