-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·95 lines (80 loc) · 2.89 KB
/
install.sh
File metadata and controls
executable file
·95 lines (80 loc) · 2.89 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
#!/usr/bin/env bash
set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BACKUP_ROOT="$HOME/.terminal_backups"
BACKUP_DIR="$BACKUP_ROOT/mac-terminal-dotfiles-$(date +%Y%m%d-%H%M%S)"
SKIP_BREW=0
log() {
printf '[mac-terminal-dotfiles] %s\n' "$*"
}
usage() {
cat <<USAGE
Usage: ./install.sh [--skip-brew]
--skip-brew Skip Homebrew dependency installation.
USAGE
}
while [[ $# -gt 0 ]]; do
case "$1" in
--skip-brew)
SKIP_BREW=1
shift
;;
-h|--help)
usage
exit 0
;;
*)
echo "Unknown argument: $1" >&2
usage
exit 1
;;
esac
done
mkdir -p "$BACKUP_DIR" "$HOME/.zsh" "$HOME/.config/iterm2" "$HOME/Library/Application Support/iTerm2/DynamicProfiles"
backup_and_link() {
local src="$1"
local dst="$2"
mkdir -p "$(dirname "$dst")"
if [[ -L "$dst" ]] && [[ "$(readlink "$dst")" == "$src" ]]; then
log "already linked: $dst"
return
fi
if [[ -e "$dst" || -L "$dst" ]]; then
local rel="${dst#$HOME/}"
mkdir -p "$BACKUP_DIR/$(dirname "$rel")"
mv "$dst" "$BACKUP_DIR/$rel"
log "backup: $dst -> $BACKUP_DIR/$rel"
fi
ln -s "$src" "$dst"
log "linked: $dst -> $src"
}
# Dotfiles
backup_and_link "$REPO_ROOT/zsh/.zshrc" "$HOME/.zshrc"
backup_and_link "$REPO_ROOT/zsh/.zsh/aliases.smartmur.zsh" "$HOME/.zsh/aliases.smartmur.zsh"
backup_and_link "$REPO_ROOT/zsh/.zsh/functions.smartmur.zsh" "$HOME/.zsh/functions.smartmur.zsh"
backup_and_link "$REPO_ROOT/zsh/.zsh/nvm.smartmur.zsh" "$HOME/.zsh/nvm.smartmur.zsh"
backup_and_link "$REPO_ROOT/zsh/.zsh/starship.smartmur.zsh" "$HOME/.zsh/starship.smartmur.zsh"
backup_and_link "$REPO_ROOT/config/.config/starship.smartmur.toml" "$HOME/.config/starship.smartmur.toml"
backup_and_link "$REPO_ROOT/config/.config/iterm2/smartmur.itermcolors" "$HOME/.config/iterm2/smartmur.itermcolors"
backup_and_link "$REPO_ROOT/config/.config/iterm2/smartmur-profile.json" "$HOME/.config/iterm2/smartmur-profile.json"
backup_and_link "$REPO_ROOT/config/.config/iterm2/smartmur.dynamic.json" "$HOME/Library/Application Support/iTerm2/DynamicProfiles/smartmur.dynamic.json"
# iTerm2 default profile
DYN_PROFILE="$HOME/Library/Application Support/iTerm2/DynamicProfiles/smartmur.dynamic.json"
if [[ -f "$DYN_PROFILE" ]]; then
PROFILE_GUID="$(plutil -extract Profiles.0.Guid raw -o - "$DYN_PROFILE" 2>/dev/null || true)"
if [[ -n "$PROFILE_GUID" ]]; then
defaults write com.googlecode.iterm2 "Default Bookmark Guid" -string "$PROFILE_GUID" || true
log "iTerm2 default profile GUID set to: $PROFILE_GUID"
fi
fi
if [[ "$SKIP_BREW" -eq 0 ]]; then
if command -v brew >/dev/null 2>&1; then
log "installing/updating Homebrew dependencies"
brew bundle --file "$REPO_ROOT/Brewfile"
else
log "Homebrew not found. Install Homebrew, then run: brew bundle --file $REPO_ROOT/Brewfile"
fi
fi
log "install complete"
log "backup directory: $BACKUP_DIR"
log "apply now: exec zsh"