-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
145 lines (119 loc) · 3.87 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
#!/bin/bash
# Inspired by https://github.com/vsbuffalo/dotfiles/blob/master/setup.sh
set -e
set -u
RCol='\033[0m'
Green='\033[0;32m'
Red='\033[0;31m'
Yellow='\033[0;33m'
## printing functions ##
function gecho {
echo "${Green}[message] $1${RCol}"
}
function yecho {
echo "${Yellow}[warning] $1${RCol}"
}
function wecho {
# red, but don't exit 1
echo "${Red}[error] $1${RCol}"
}
function recho {
echo "${Red}[error] $1${RCol}"
exit 1
}
# check for pre-req, fail if not found
function check_preq {
(command -v $1 > /dev/null && gecho "$1 found...") ||
recho "$1 not found, install before proceeding."
}
# function for linking dotfiles
function linkdotfile {
source_file="$1"
dest_file="$2"
if [ -z "$dest_file" ]; then
dest_file="$source_file"
fi
if [ ! -e "$HOME/$dest_file" ] && [ ! -L "$HOME/$dest_file" ]; then
yecho "$dest_file not found, linking..." >&2
ln -s "$HOME/dotfiles/$source_file" "$HOME/$dest_file"
else
gecho "$dest_file found, ignoring.." >&2
if [ ! -L "$HOME/$dest_file" ]; then
wecho "$dest_file is a regular file, not a symlink. You may need to manually create the symlink or delete the file in its place before running the script again"
fi
fi
}
# Check/install NVM if does not exist
check_and_install_nvm() {
# Source NVM script to make sure it's available in the current shell session
if [ -s "$HOME/.nvm/nvm.sh" ]; then
\. "$HOME/.nvm/nvm.sh"
fi
if command -v nvm > /dev/null 2>&1; then
gecho "NVM already installed"
else
yecho "NVM not found, installing..."
# Download and install NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
gecho "NVM installation complete"
fi
}
install_volta() {
# Check if ~/.volta directory exists
if [ -d "$HOME/.volta" ]; then
gecho "Volta already installed"
else
yecho "Volta not found. Installing..."
# Install Volta
curl https://get.volta.sh | bash -s -- --skip-setup
fi
}
install_oh_my_zsh() {
# Check if ~/.oh-my-zsh directory exists
if [ -d "$HOME/.oh-my-zsh" ]; then
gecho "Oh My Zsh already installed"
else
yecho "Oh My Zsh not found. Installing..."
# Install Oh My Zsh
KEEP_ZSHRC=yes RUNZSH=no CHSH=no sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
fi
}
install_tmux_tpm() {
# check if $HOME/.tmux/plugins/tpm directory exists
if [ -d "$HOME/.tmux/plugins/tpm" ]; then
gecho "Tmux TPM already installed"
else
yecho "Tmux TPM not found. Installing..."
# Install tmp tmux plugin
git clone https://github.com/tmux-plugins/tpm $HOME/.tmux/plugins/tpm
fi
}
# check for pre-req, fail if not found
function check_preq {
(command -v $1 > /dev/null && gecho "$1 found...") ||
recho "$1 not found, install before proceeding."
}
# are we in right directory?
[[ $(basename $(pwd)) == "dotfiles" ]] ||
recho "doesn't look like you're in dotfiles/"
# check that the key pre-requisites are met:
check_preq brew
# Linking
linkdotfile git/.gitconfig .gitconfig
linkdotfile zsh/rc.zsh .zshrc
linkdotfile nvim .config/nvim
linkdotfile editor/.editorconfig .editorconfig
linkdotfile tmux/.tmux.conf .tmux.conf
linkdotfile wezterm/config.lua .wezterm.lua
linkdotfile linearmouse/config.json .config/linearmouse/linearmouse.json
linkdotfile rectangle/config.json Library/Application\ Support/Rectangle/RectangleConfig.json
linkdotfile vscode/settings.json Library/Application\ Support/Code/User/settings.json
linkdotfile vscode/keybindings.json Library/Application\ Support/Code/User/keybindings.json
## Install NVM if it doesn't exist. If it does exist, it will NVM will be updated.
## check_and_install_nvm
## Install oh my zsh if it doesn't exist
install_oh_my_zsh
## Install Tmux TPM plugin if it doesn't exist
install_tmux_tpm
## Install Volta if it doesn't exist
install_volta