Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·97 lines (82 loc) · 2.43 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·97 lines (82 loc) · 2.43 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
#!/usr/bin/env bash
set -euo pipefail
repo_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
install_packages=false
usage() {
cat <<'EOF'
Usage: ./install.sh [--brew]
Link this repository's configuration into the current home directory.
Existing files are never overwritten. Pass --brew to install packages from
the Brewfile before creating links.
EOF
}
while (($#)); do
case "$1" in
--brew) install_packages=true ;;
-h|--help) usage; exit 0 ;;
*) printf 'Unknown option: %s\n' "$1" >&2; usage >&2; exit 2 ;;
esac
shift
done
if $install_packages; then
if ! command -v brew >/dev/null 2>&1; then
printf 'Homebrew is required. Install it from https://brew.sh and try again.\n' >&2
exit 1
fi
brew bundle --file "$repo_dir/Brewfile"
fi
links=(
"ackrc:$HOME/.ackrc"
"bashrc:$HOME/.bashrc"
"gemrc:$HOME/.gemrc"
"gitconfig:$HOME/.gitconfig"
"gitconfig.amber:$HOME/.gitconfig.amber"
"gitignore_global:$HOME/.gitignore_global"
"nvim:$HOME/.config/nvim"
"vimrc:$HOME/.vimrc"
"gvimrc:$HOME/.gvimrc"
"zshrc:$HOME/.zshrc"
)
case "$(uname -s)" in
Darwin)
links+=("vscode/settings.json:$HOME/Library/Application Support/Code/User/settings.json")
;;
Linux)
links+=("vscode/settings.json:$HOME/.config/Code/User/settings.json")
;;
*)
printf 'Unsupported operating system: %s\n' "$(uname -s)" >&2
exit 1
;;
esac
conflicts=0
for entry in "${links[@]}"; do
source_path="$repo_dir/${entry%%:*}"
target_path="${entry#*:}"
if [[ -L "$target_path" ]] && [[ "$(readlink "$target_path")" == "$source_path" ]]; then
printf 'ok %s\n' "$target_path"
continue
fi
if [[ -e "$target_path" || -L "$target_path" ]]; then
printf 'conflict %s (left unchanged)\n' "$target_path" >&2
conflicts=$((conflicts + 1))
continue
fi
mkdir -p "$(dirname "$target_path")"
ln -s "$source_path" "$target_path"
printf 'linked %s -> %s\n' "$target_path" "$source_path"
done
# Seed an empty machine-local shell file for secrets / per-machine config.
# It is sourced by zshrc but deliberately never tracked in this repo.
local_shell="$HOME/.zshrc.local"
if [[ ! -e "$local_shell" ]]; then
cat >"$local_shell" <<'EOF'
# Machine-specific and secret shell config. Not tracked in git.
# Add API keys, tokens, and per-machine PATH tweaks here.
EOF
printf 'created %s\n' "$local_shell"
fi
if ((conflicts)); then
printf '\n%d conflict(s) require manual review.\n' "$conflicts" >&2
exit 1
fi