-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·172 lines (139 loc) · 4.22 KB
/
bootstrap.sh
File metadata and controls
executable file
·172 lines (139 loc) · 4.22 KB
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
#!/usr/bin/env bash
set -euo pipefail
[ ${DEBUG:-} ] && set -x
node_version=""
ruby_version=""
python_version=""
while getopts ":n:r:p:" opt; do
case $opt in
n) node_version="$OPTARG"
;;
r) ruby_version="$OPTARG"
;;
p) python_version="$OPTARG"
;;
\?) echo "Invalid option -$OPTARG" >&2
;;
esac
done
function link() {
source="${PWD}/${1}"
target=${2:-"${HOME}/.${1}"}
echo "Linking ${source} -> ${target}"
ln -snf "${source}" "${target}"
}
function is_exec() {
[ -x $(which "${1}") ]
}
function fetch_shell_config() {
local local_file="${HOME}/.zshrc"
local remote_file="https://git.grml.org/f/grml-etc-core/etc/zsh/zshrc"
# Check if the local file is older than 1 month
local expiry_timestamp=$(date -v -1m +%s)
local local_last_modified=$(stat -f %m "${local_file}" 2>/dev/null || echo "0")
if [ ! -f "${local_file}" ] || [ "${local_last_modified}" -lt "${expiry_timestamp}" ]; then
echo "Shell config: fetching zshrc: ${remote_file} -> ${local_file}"
curl -fLo "${local_file}" "${remote_file}"
else
echo "Shell config: zshrc is up to date"
fi
}
function install_node() {
echo "Installing node ${node_version}"
asdf plugin add nodejs "https://github.com/asdf-vm/asdf-nodejs.git"
asdf install nodejs "${node_version}"
asdf set --home nodejs "${node_version}"
corepack enable
}
function install_ruby() {
echo "Installing ruby ${ruby_version}"
asdf plugin add ruby "https://github.com/asdf-vm/asdf-ruby.git"
asdf install ruby "${ruby_version}"
asdf set --home ruby "${ruby_version}"
}
function install_python() {
echo "Installing python ${python_version}"
asdf plugin add python "https://github.com/danhper/asdf-python.git"
asdf install python "${python_version}"
asdf set --home python "${python_version}"
}
function install_default_packages() {
local filename=$1
local install_command=$2
local lines=()
while IFS= read -r line; do
lines+=("$line")
done < "$filename"
$install_command "${lines[@]}"
}
function install_or_update_tmux_package_manager() {
local tpm_dir="${HOME}/.tmux/plugins/tpm"
if [ -d "${tpm_dir}" ]; then
echo "Updating tmux plugin manager"
git -C "${tpm_dir}" pull
else
echo "Installing tmux plugin manager"
git clone https://github.com/tmux-plugins/tpm "${tpm_dir}"
fi
}
# Homebrew
brew bundle
# Shell config from grml (https://grml.org/zsh/)
fetch_shell_config
# Link dotfiles
link "zshrc.pre"
link "zshrc.local"
link "zshrc.custom.local"
link "bin"
link "asdfrc"
link "gemrc"
link "gitconfig"
link "gitignore"
link "hushlogin"
link "tmux.conf"
link "editorconfig"
mkdir -p "${HOME}/.config/ghostty"
link "config/ghostty/config" "${HOME}/.config/ghostty/"
mkdir -p "${HOME}/.config/fish"
link "config/fish/config.fish" "${HOME}/.config/fish/"
link "config/fish/config.local.fish" "${HOME}/.config/fish/"
link "config/fish/functions" "${HOME}/.config/fish/"
mkdir -p "${HOME}/.config/nvim/queries/gotmpl"
link "config/nvim/init.vim" "${HOME}/.config/nvim/"
link "config/nvim/queries/gotmpl/injections.scm" "${HOME}/.config/nvim/queries/gotmpl/"
link "default-npm-packages"
link "default-gems"
link "default-python-packages"
# continue on error installing languages
set +e
# Node
[[ "${node_version}" ]] && install_node
if is_exec node; then
install_default_packages "default-npm-packages" "npm install -g"
asdf reshim nodejs
fi
# Ruby
[[ "${ruby_version}" ]] && install_ruby
if is_exec ruby; then
install_default_packages "default-gems" "gem install"
asdf reshim ruby
fi
# Python
[[ "${python_version}" ]] && install_python
if is_exec python; then
install_default_packages "default-python-packages" "pip install"
asdf reshim python
fi
# exit on error again
set -e
# Install Vim Plug
curl -fLo "${HOME}/.local/share/nvim/site/autoload/plug.vim" --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
nvim +PlugUpgrade +PlugInstall +PlugUpdate +PlugClean! +MasonUpdate +qa
# Setup fzf
$(brew --prefix)/opt/fzf/install --key-bindings --completion --no-update-rc
# Setup asdf
mkdir -p "${HOME}/.asdf/completions/zsh"
asdf completion zsh > "${HOME}/.asdf/completions/zsh/_asdf"
asdf completion fish > ~/.config/fish/completions/asdf.fish
# Tmux plugin manager
install_or_update_tmux_package_manager