-
Notifications
You must be signed in to change notification settings - Fork 46
/
setup.sh
194 lines (158 loc) · 5.3 KB
/
setup.sh
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/usr/bin/env bash
################################################################################
# setup.sh
#
# This script uses GNU Stow to symlink files and directories into place.
# It can be run safely multiple times on the same machine. (idempotency)
################################################################################
dotfiles_echo() {
local fmt="$1"
shift
# shellcheck disable=SC2059
printf "\\n[DOTFILES] ${fmt}\\n" "$@"
}
backup_stow_conflict() {
dotfiles_echo "Conflict detected: ${1} Backing up.."
local BACKUP_SUFFIX
BACKUP_SUFFIX="$(date +%Y-%m-%d)_$(date +%s)"
mv -v "$1" "${1}_${BACKUP_SUFFIX}"
}
osname=$(uname)
if [ "$osname" != "Darwin" ]; then
dotfiles_echo "Oops, it looks like you're using a non-Apple system. Sorry, this script only supports macOS. Exiting..."
exit 1
fi
if ! command -v stow >/dev/null; then
dotfiles_echo "GNU Stow is required but was not found. Try: brew install stow"
dotfiles_echo "Exiting..."
exit 1
fi
dotfiles_echo "Initializing dotfiles setup..."
sudo -v
set -e # Terminate script if anything exits with a non-zero value
if [ -z "$DOTFILES" ]; then
export DOTFILES="${HOME}/dotfiles"
fi
dotfiles_echo "Setting HostName..."
COMPUTER_NAME=$(scutil --get ComputerName)
LOCAL_HOST_NAME=$(scutil --get LocalHostName)
sudo scutil --set HostName "$LOCAL_HOST_NAME"
HOST_NAME=$(scutil --get HostName)
sudo defaults write /Library/Preferences/SystemConfiguration/com.apple.smb.server.plist NetBIOSName -string "$HOST_NAME"
printf "ComputerName: ==> [%s]\\n" "$COMPUTER_NAME"
printf "LocalHostName: ==> [%s]\\n" "$LOCAL_HOST_NAME"
printf "HostName: ==> [%s]\\n" "$HOST_NAME"
if [ -z "$XDG_CONFIG_HOME" ]; then
dotfiles_echo "Setting up ~/.config directory..."
if [ ! -d "${HOME}/.config" ]; then
mkdir "${HOME}/.config"
fi
export XDG_CONFIG_HOME="${HOME}/.config"
fi
if [ ! -d "${HOME}/.local/bin" ]; then
dotfiles_echo "Setting up ~/.local/bin directory..."
mkdir -pv "${HOME}/.local/bin"
fi
dotfiles_echo "Checking your system architecture..."
arch="$(uname -m)"
if [ "$arch" == "arm64" ]; then
dotfiles_echo "You're on Apple Silicon! Setting HOMEBREW_PREFIX to /opt/homebrew..."
HOMEBREW_PREFIX="/opt/homebrew"
else
dotfiles_echo "You're on an Intel Mac! Setting HOMEBREW_PREFIX to /usr/local..."
HOMEBREW_PREFIX="/usr/local"
fi
dotfiles_echo "Checking for potential stow conflicts..."
cd "${DOTFILES}/" # stow needs to run from inside dotfiles dir
stow_conflicts=(
".asdfrc"
".bashrc"
".config/fish"
".config/kitty"
".config/lazygit"
".config/lvim"
".config/nvim"
".config/starship.toml"
".config/tmux"
".config/yamllint"
".config/zsh"
".config/zsh-abbr"
".default-gems"
".default-npm-packages"
".gemrc"
".gitconfig"
".gitignore_global"
".gitmessage"
".hushlogin"
".irbrc"
".laptop.local"
".local/bin/colortest"
".local/bin/git-brst"
".local/bin/git-cm"
".local/bin/git-publish"
".local/bin/git-uncommit"
".local/bin/tat"
".npmrc"
".pryrc"
".ripgreprc"
".rubocop.yml"
".tool-versions"
".zshrc"
"Brewfile"
)
for item in "${stow_conflicts[@]}"; do
if [ -e "${HOME}/${item}" ]; then
# Potential conflict detected
if [ -L "${HOME}/${item}" ]; then
# This is a symlink and we can ignore it.
continue
elif [ "$item" == ".tool-versions" ]; then
# This was likely generated by Laptop, and we actually want to adopt it for now.
dotfiles_echo "${HOME}/.tool-versions file found. Adopting..."
stow --adopt asdf/
else
# This is a file or directory that will cause a conflict.
backup_stow_conflict "${HOME}/${item}"
fi
fi
done
dotfiles_echo "Setting up symlinks with GNU Stow..."
for item in *; do
if [ -d "$item" ]; then
stow "$item"/
fi
done
if command -v fish &>/dev/null; then
dotfiles_echo "Initializing fish_user_paths..."
command fish -c "set -U fish_user_paths $HOME/.asdf/shims $HOME/.local/bin $HOME/.bin $HOME/.yarn/bin $HOMEBREW_PREFIX/bin"
fi
if [ -d "/Applications/iTerm.app" ]; then
dotfiles_echo "Setting up iTerm2 preferences..."
# Specify the preferences directory
defaults write com.googlecode.iterm2.plist PrefsCustomFolder -string "$DOTFILES/iterm"
# Tell iTerm2 to use the custom preferences in the directory
defaults write com.googlecode.iterm2.plist LoadPrefsFromCustomFolder -bool true
fi
if command -v tmux &>/dev/null; then
if [ ! -d "${HOME}/.terminfo" ]; then
dotfiles_echo "Installing custom terminfo entries..."
# These entries enable, among other things, italic text in the terminal.
tic -x "${DOTFILES}/terminfo/tmux-256color.terminfo"
tic -x "${DOTFILES}/terminfo/xterm-256color-italic.terminfo"
fi
if [ ! -d "${DOTFILES}/tmux/.config/tmux/plugins" ]; then
dotfiles_echo "Installing Tmux Plugin Manager..."
git clone https://github.com/tmux-plugins/tpm "${DOTFILES}/tmux/.config/tmux/plugins/tpm"
fi
fi
dotfiles_echo "Dotfiles setup complete!"
echo
echo "Possible next steps:"
echo "-> Install Zap (https://www.zapzsh.org)"
echo "-> Install Homebrew packages (brew bundle install)"
if command -v tmux &>/dev/null; then
echo "-> Install Tmux plugins with <prefix> + I (https://github.com/tmux-plugins/tpm)"
fi
echo "-> Set up 1Password CLI (https://developer.1password.com/docs/cli)"
echo "-> Check out documentation for LazyVim (https://www.lazyvim.org/)"
echo