-
Notifications
You must be signed in to change notification settings - Fork 35
/
fresh-brew.local
115 lines (97 loc) · 3.53 KB
/
fresh-brew.local
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
108
109
110
111
112
113
114
115
#!/usr/bin/env bash
##### START OF HELPER FUNCTIONS #####
# If asdf stops working, it might be because the setup commands changed.
# Check the documentation: https://asdf-vm.com/guide/getting-started.html#_3-install-asdf
configure_shell_file_for_asdf() {
if [[ $SHELL == *fish ]]; then
# shellcheck disable=SC2154
append_to_file "$shell_file" "source (brew --prefix asdf)/libexec/asdf.fish"
else
# shellcheck disable=SC2154
append_to_file "$shell_file" "source $(brew --prefix asdf)/libexec/asdf.sh"
fi
}
install_asdf_tools() {
go_version="$(awk '/golang/ { print $2 }' .tool-versions)"
if ! asdf_plugin_is_installed "golang"; then
fancy_echo "Adding golang plugin to asdf..."
asdf plugin add golang
else
fancy_echo "Updating asdf golang plugin..."
asdf plugin update golang
fi
if ! asdf_plugin_is_installed "nodejs"; then
fancy_echo "Adding nodejs plugin to asdf..."
asdf plugin add nodejs
else
fancy_echo "Updating asdf nodejs plugin..."
asdf plugin update nodejs
fi
fancy_echo "Installing asdf managed tools from .tool-versions..."
asdf install
fancy_echo "Setting global golang version to $go_version ..."
asdf global golang "$go_version"
}
asdf_plugin_is_installed() {
asdf plugin list -1 | grep -Fqx "$1"
}
configure_shell_file_for_gopath() {
if [[ $SHELL == *fish ]]; then
append_to_file "$shell_file" "set -x GOPATH (go env GOPATH)"
# shellcheck disable=SC2016
append_to_file "$shell_file" 'set -g fish_user_paths "$GOPATH/bin" $fish_user_paths'
else
# shellcheck disable=SC2016
append_to_file "$shell_file" 'export GOPATH=${GOPATH:-$(go env GOPATH)}'
# shellcheck disable=SC2016
append_to_file "$shell_file" 'export PATH=$(go env GOPATH)/bin:$PATH'
fi
}
# If direnv stops working, it might be because the setup commands changed.
# Check the documentation:
# https://github.com/direnv/direnv/blob/master/docs/hook.md
configure_shell_file_for_direnv() {
if [[ $SHELL == *fish ]]; then
append_to_file "$shell_file" "direnv hook fish | source"
elif [[ $SHELL == *zsh ]]; then
# shellcheck disable=SC2016
append_to_file "$shell_file" 'eval "$(direnv hook zsh)"'
elif [[ $SHELL == *bash ]]; then
# shellcheck disable=SC2016
append_to_file "$shell_file" 'eval "$(direnv hook bash)"'
fi
}
cask_is_installed() {
brew list -1 --cask | grep -Fqx "$1"
}
app_is_in_applications_folder() {
find "/Applications" -maxdepth 1 -name "$1"
}
docker_installed_outside_of_brew() {
! cask_is_installed "docker" && app_is_in_applications_folder "Docker"
}
##### END OF HELPER FUNCTIONS #####
fancy_echo "Running your customizations from fresh-brew.local ..."
if [ -f "Brewfile.local" ]; then
if brew bundle --file="Brewfile.local"; then
fancy_echo "All items in Brewfile.local were installed successfully."
else
fancy_echo "Some items in Brewfile.local were not installed successfully."
fi
fi
if ! docker_installed_outside_of_brew; then
brew bundle --file=- <<EOF
cask 'docker'
EOF
fi
configure_shell_file_for_asdf
install_asdf_tools
configure_shell_file_for_gopath
# make sure that any functions that write to the shell file appear before this
# direnv function below because the direnv line has to be at the very end of the
# shell file.
configure_shell_file_for_direnv
fancy_echo "******* IMPORTANT **************************************"
fancy_echo "If you get errors below, quit and restart your terminal,"
fancy_echo "or open a new tab, and run 'make deps' again."
fancy_echo "********************************************************"