-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathinstall
More file actions
executable file
·78 lines (63 loc) · 2.25 KB
/
install
File metadata and controls
executable file
·78 lines (63 loc) · 2.25 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
#!/usr/bin/env zsh
#/ DESCRIPTION:
#/ Install Homebrew packages from machine-specific Brewfiles.
#/ Combines Brewfile, Brewfile.optional, Brewfile.{work|personal}, and Brewfile.vsc
#/ 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"
# Machine hostnames (change these to match your machines)
typeset -r WORK_MACHINE_NAME="0x73746f65"
typeset -r PERSONAL_MACHINE_NAME="6x73746f65"
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
# Add VS Code extensions
[[ ! -f Brewfile.vsc ]] && abort "Brewfile.vsc not found" && exit 1
brewfile_all="${brewfile_all}\n\n$(cat Brewfile.vsc)"
# Write unified Brewfile
echo "$brewfile_all" > "$BREWFILE_LOCAL"
# Execute brew bundle install
typeset cmd="brew bundle --file $BREWFILE_LOCAL"
formatexec "$cmd"
echo ""
ok "homebrew 🍺 done"