-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_env.sh
executable file
·155 lines (136 loc) · 3.2 KB
/
setup_env.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
#! /usr/bin/env zsh
# exit immediately on failure
set -eo pipefail
# Setting variables for decisions, getopts will override these.
all=1
brew=0
stow=0
unstow=0
nvim=0
package=0
die() {
printf '%s\n' "$1" >&2
exit 1
}
show_help() {
echo "This script takes in the following values:"
echo "[-h|--help] - Displays this help message."
echo "[-b|--brew] - Runs brew bundle."
echo "[-s|--stow] - Runs stow against the dotfiles."
echo "[-n|--nvim] - Runs install of NVIM plugins."
echo "[-p|--package] - Runs install of other packages."
}
brew_install() {
if [ -f "Brewfile" ]
then
echo "Installing brew dependencies..."
brew bundle --force
else
echo "Brewfile does not exist, skipping dependency installs..."
fi
}
stow_files() {
if (! command -v stow) && [[ $stow == 1 || $all = 1 ]]
then
echo "Stow does not exist, exiting..."
exit 1
else
# backup the previous .zshrc file incase it exists but isn't a symlinked file
# - pertinent on brand new setups
if [[ (! -L "$HOME/.zsrhc") && (-f "$HOME/.zshrc") ]]
then
echo "Backing up original .zshrc"
mv $HOME/.zshrc $HOME/.zshrc.bak
fi
echo "Stowing directory"
stow . --restow --target=$HOME
fi
}
unstow_files() {
if (command -v stow)
then
echo "Unstowing files."
stow -D .
else
echo "The Stow command doesn't exist."
exit 1
fi
}
nvim_setup() {
nvim -c 'TSUpdate' +qall
}
package_install() {
# Install NPM LSPs
npm install -g pyright
npm install -g bash-language-server
npm install -g vscode-langservers-extracted
npm install -g typescript typescript-language-server
# Install Yarn LSPs
yarn global add yaml-language-server
# Install other NPM packages
npm install -g semantic-release
# Install Go packages
go install golang.org/x/tools/gopls@latest
go install github.com/securego/gosec/v2/cmd/gosec@latest
go install honnef.co/go/tools/cmd/staticcheck@latest
go install golang.org/x/tools/cmd/goimports@latest
}
while :; do
case $1 in
-h|-\?|--help)
show_help # Display a usage synopsis.
all=0
exit
;;
-b|--brew)
brew=1
all=0
;;
-s|--stow)
stow=1
all=0
;;
-u|--unstow)
unstow=1
all=0
;;
-n|--nvim)
nvim=1
all=0
;;
-p|--package)
package=1
all=0
;;
--) # End of all options.
shift
break
;;
-?*)
printf 'WARN: Unknown option (ignored): %s\n' "$1" >&2
;;
*) # Default case: No more options, so break out of the loop.
break
esac
shift
done
if [ $brew = 1 ] || [ $all = 1 ]
then
brew_install
fi
if [ $unstow = 1 ]
then
unstow_files
fi
if [ $stow = 1 ] || [ $all = 1 ]
then
stow_files
fi
if [ $nvim = 1 ] || [ $all = 1 ]
then
nvim_setup
fi
if [ $package = 1 ] || [ $all = 1 ]
then
package_install
fi