-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·103 lines (90 loc) · 2.82 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·103 lines (90 loc) · 2.82 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
#!/usr/bin/env bash
#
# Idempotent installer for the framework-free zsh setup.
#
# Defaults to a dry run — prints what it would do without touching $HOME.
# Pass --apply to actually symlink files and back up anything in the way.
#
# ./install.sh # dry run (default)
# ./install.sh --apply # do it for real
#
set -euo pipefail
DOTFILES_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BACKUP_DIR="$HOME/.dotfiles-backup/$(date +%Y%m%d%H%M%S)"
APPLY=0
for arg in "$@"; do
case "$arg" in
--apply) APPLY=1 ;;
--dry-run) APPLY=0 ;;
*)
echo "Unknown argument: $arg" >&2
echo "Usage: $0 [--apply|--dry-run]" >&2
exit 1
;;
esac
done
if [[ "$APPLY" -eq 0 ]]; then
echo "-- DRY RUN -- no files will be changed. Re-run with --apply to install."
fi
# name -> source path (relative to $DOTFILES_DIR), symlinked to ~/name
LINKS=(
".zshrc:.zshrc"
".zsh_plugins.txt:.zsh_plugins.txt"
".config/starship.toml:starship.toml"
".zalias:zsh/.zalias"
".zexports:zsh/.zexports"
".zfunc:zsh/.zfunc"
".p10k.zsh:p10"
"Library/Application Support/iTerm2/DynamicProfiles/dotfiles.json:iterm2/DynamicProfiles.json"
"Library/Fonts/Meslo LG L DZ Regular for Powerline.otf:fonts/Meslo LG L DZ Regular for Powerline.otf"
".config/nvim:nvim"
)
backup_if_needed() {
local target="$1"
if [[ -e "$target" || -L "$target" ]]; then
if [[ "$APPLY" -eq 1 ]]; then
mkdir -p "$BACKUP_DIR"
mv "$target" "$BACKUP_DIR/"
echo "backed up existing $target -> $BACKUP_DIR/"
else
echo "would back up existing $target -> $BACKUP_DIR/"
fi
fi
}
link_one() {
local dest_name="$1" src_rel="$2"
local src="$DOTFILES_DIR/$src_rel"
local dest="$HOME/$dest_name"
if [[ -L "$dest" && "$(readlink "$dest")" == "$src" ]]; then
echo "already linked: $dest"
return
fi
backup_if_needed "$dest"
if [[ "$APPLY" -eq 1 ]]; then
mkdir -p "$(dirname "$dest")"
ln -s "$src" "$dest"
echo "linked $dest -> $src"
else
echo "would link $dest -> $src"
fi
}
for entry in "${LINKS[@]}"; do
dest_name="${entry%%:*}"
src_rel="${entry#*:}"
link_one "$dest_name" "$src_rel"
done
echo
echo "Homebrew packages (antidote, starship, eza, fzf, ...) are listed in Brewfile."
if [[ "$APPLY" -eq 1 ]]; then
echo "Run 'brew bundle --file=$DOTFILES_DIR/Brewfile' to install them."
else
echo "would suggest: brew bundle --file=$DOTFILES_DIR/Brewfile"
fi
echo
echo "iTerm2: the 'Gargantua' and 'Default' profiles from the old"
echo "com.googlecode.iterm2.plist are now available as a Dynamic Profile."
echo "Open iTerm2 -> Preferences -> Profiles to see them (no restart needed,"
echo "this does NOT overwrite your current iTerm preferences or profiles)."
echo
echo "This script never changes your default shell or touches ~/.zprezto."
echo "To switch shells yourself: chsh -s \$(which zsh)"