-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinstall
More file actions
executable file
·107 lines (88 loc) · 3.23 KB
/
Copy pathinstall
File metadata and controls
executable file
·107 lines (88 loc) · 3.23 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
105
106
107
#!/usr/bin/env zsh
#/ DESCRIPTION:
#/ Install Homebrew packages from machine-specific Brewfiles.
#/ Combines Brewfile, Brewfile.optional, and Brewfile.{work|personal}
#/ into a unified Brewfile.local based on the current machine hostname.
#/
#/ USAGE:
#/ install
setopt ERR_EXIT PIPE_FAIL
# Source helper functions if not already loaded
typeset -r SCRIPT_DIR="${0:A:h}"
typeset -r DOTFILES_ROOT="${SCRIPT_DIR:h:h}"
if [[ ! $(typeset -f section) ]]; then
source "${DOTFILES_ROOT}/inc/helpers.zsh"
fi
# Change to script directory to find Brewfiles
cd "$SCRIPT_DIR"
sync_vscode_extensions() {
typeset cli_name="$1"
typeset editor_name="$2"
typeset -a desired_extensions
typeset extension
if ! command -v "$cli_name" >/dev/null 2>&1; then
disabled
print -P "%244FSkipping $editor_name extension sync (missing CLI: $cli_name)%f"
return 0
fi
desired_extensions=("${(@f)$(sed -nE 's/^[[:space:]]*vscode[[:space:]]+"([^"]+)".*/\1/p' Brewfile.vsc)}")
for extension in "${desired_extensions[@]}"; do
# --force handles install and update with one command.
formatexec "$cli_name --install-extension $extension --force"
done
}
# Machine hostnames (change these to match your machines)
typeset -r WORK_MACHINE_NAME="$(op read 'op://Private/brewfiles/WORK_MACHINE/name')"
typeset -r PERSONAL_MACHINE_NAME="$(op read 'op://Private/brewfiles/PERSONAL_MACHINE/name')"
typeset -r BREWFILE_LOCAL="Brewfile.local"
# Cleanup trap to remove temporary Brewfile.local on exit
cleanup_brewfile() {
[[ -f "$BREWFILE_LOCAL" ]] && rm -f "$BREWFILE_LOCAL" "${BREWFILE_LOCAL}.lock.json"
}
trap cleanup_brewfile EXIT INT TERM
section "homebrew" "🍺 💻 install"
# Verify required Brewfiles exist
[[ ! -f Brewfile ]] && abort "Brewfile not found" && exit 1
[[ ! -f Brewfile.optional ]] && abort "Brewfile.optional not found" && exit 1
# Get the local computer's hostname
typeset machine_name
machine_name=$(hostname)
# Combine base Brewfiles
typeset brewfile_all
brewfile_all="$(cat Brewfile)\n\n$(cat Brewfile.optional)"
# Load machine-specific Brewfile based on hostname
case "$machine_name" in
"$WORK_MACHINE_NAME")
section "homebrew" "🍺 💼"
[[ ! -f Brewfile.work ]] && abort "Brewfile.work not found" && exit 1
brewfile_all="${brewfile_all}\n\n$(cat Brewfile.work)"
;;
"$PERSONAL_MACHINE_NAME")
section "homebrew" "🍺 🏡"
[[ ! -f Brewfile.personal ]] && abort "Brewfile.personal not found" && exit 1
brewfile_all="${brewfile_all}\n\n$(cat Brewfile.personal)"
;;
*)
abort "Unknown machine name: $machine_name"
exit 1
;;
esac
# Write unified Brewfile
echo "$brewfile_all" > "$BREWFILE_LOCAL"
# Execute brew bundle install
typeset cmd="brew bundle --file $BREWFILE_LOCAL"
formatexec "$cmd"
# Sync extension state in both VS Code Stable and Insiders.
[[ ! -f Brewfile.vsc ]] && abort "Brewfile.vsc not found" && exit 1
section "vscode" "🧩 insiders"
sync_vscode_extensions "code-insiders" "VS Code Insiders" || {
disabled
print -P "%244FVS Code Insiders extension sync reported errors; continuing%f"
}
section "vscode" "🧩 stable"
sync_vscode_extensions "code" "VS Code Stable" || {
disabled
print -P "%244FVS Code Stable extension sync reported errors; continuing%f"
}
echo ""
ok "homebrew 🍺 done"