-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.sh
executable file
·82 lines (65 loc) · 2 KB
/
init.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
#!/usr/bin/env bash
cd "$(dirname "$0")"
set -o errexit -o noclobber -o nounset
help() {
echo "
Configure macOS for first-time use.
USAGE:
init [OPTION] [ARGS...]
OPTIONS:
--init Idempotent initialization of dependencies
--symlink Symlink dotfiles in home directory
-h, --help Display help
"
}
init() {
echo "Initializing $(whoami)'s dev dependencies..."
sudo -v
mkdir -p "$HOME/dev"
ohMyZsh=$HOME/.oh-my-zsh
if [ ! -d "$ohMyZsh" ]; then
echo "Installing oh-my-zsh..."
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
rm "$HOME/.bash_profile"
fi
if [ ! -f /opt/homebrew/bin/brew ]; then
echo "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> "$HOME/.zshrc"
eval "$(/opt/homebrew/bin/brew shellenv)"
fi
brew bundle
asdf plugin add nodejs https://github.com/asdf-vm/asdf-nodejs.git
echo "Initialization complete, open a new terminal tab/window."
# Must be last, nothing after this command will execute
env zsh -l
}
symlink() {
local dir="$HOME/dev/trs/dotfiles"
local backup_dir="$HOME/dev/trs/dotfiles_backup"
local files=".alfred .config/starship.toml .gnupg/gpg-agent.conf .oh-my-zsh/custom .ssh/config .gitconfig .zshrc"
# Backup existing, then create symlinks
for f in $files; do
echo "Backing up existing dotfiles and creating $HOME/$f symlink..."
mv "$HOME/$f" "$backup_dir"
ln -s "$dir/$f" "$HOME/$f"
done
}
parse_args() {
[ "$#" -eq 0 ] && help && exit 0;
while [ "$#" -gt 0 ]; do
case "$1" in
--init) shift; do_init=1;;
--symlink) shift; do_symlink=1;;
-h|--help) shift; help;;
-*) echo "Unknown option: $1" >&2; help; exit 1;;
*) shift;;
esac
done
if [ -n "${do_init-}" ]; then init; fi
if [ -n "${do_symlink-}" ]; then symlink; fi
}
main() {
parse_args "$@"
}
main "$@"