-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall
More file actions
executable file
·252 lines (210 loc) · 6.02 KB
/
install
File metadata and controls
executable file
·252 lines (210 loc) · 6.02 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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
#!/usr/bin/env bash
set -e
DOTFILES="$(pwd)"
BACKUP_DIR="$HOME/dotfiles-backup"
BACKUP_RUN_DIR=""
COLOR_GRAY="\033[1;38;5;243m"
COLOR_BLUE="\033[1;34m"
COLOR_GREEN="\033[1;32m"
COLOR_RED="\033[1;31m"
COLOR_PURPLE="\033[1;35m"
COLOR_YELLOW="\033[1;33m"
COLOR_NONE="\033[0m"
title() {
echo -e "\n${COLOR_PURPLE}$1${COLOR_NONE}"
echo -e "${COLOR_GRAY}==============================${COLOR_NONE}\n"
}
error() {
echo -e "${COLOR_RED}Error: ${COLOR_NONE}$1"
exit 1
}
warning() {
echo -e "${COLOR_YELLOW}Warning: ${COLOR_NONE}$1"
}
info() {
echo -e "${COLOR_BLUE}Info: ${COLOR_NONE}$1"
}
success() {
echo -e "${COLOR_GREEN}$1${COLOR_NONE}"
}
get_linkables() {
find -H "$DOTFILES" -maxdepth 3 -name '*.symlink'
}
backup_run_dir() {
local ts
ts="$(date +%Y%m%d-%H%M%S)"
echo "${BACKUP_DIR%/}/$ts"
}
backup_path_for() {
local dest="$1"
if [[ "$dest" == "$HOME" ]]; then
echo ".home"
return 0
fi
if [[ "$dest" == "$HOME/"* ]]; then
echo "${dest#"$HOME/"}"
return 0
fi
dest="${dest#/}"
echo "_external/$dest"
}
force_link() {
local source="$1"
local dest="$2"
if [ -e "$dest" ] || [ -L "$dest" ]; then
info "Removing existing ~${dest#$HOME}"
rm -rf "$dest"
fi
info "Creating symlink for $source"
ln -s "$source" "$dest"
}
backup() {
echo "Creating backup directory at $BACKUP_DIR"
mkdir -p "$BACKUP_DIR"
BACKUP_RUN_DIR="$(backup_run_dir)"
mkdir -p "$BACKUP_RUN_DIR"
info "Backing up existing targets into $BACKUP_RUN_DIR"
backup_target_if_present() {
local dest="$1"
if [ -e "$dest" ] && [ ! -L "$dest" ]; then
local rel out
rel="$(backup_path_for "$dest")"
out="$BACKUP_RUN_DIR/$rel"
mkdir -p "$(dirname "$out")"
cp -a "$dest" "$out"
fi
}
for file in $(get_linkables); do
filename="$(basename "$file" '.symlink')"
target="$HOME/$filename"
backup_target_if_present "$target"
done
config_files=$(find "$DOTFILES/config" -mindepth 1 -maxdepth 1 2>/dev/null)
for config in $config_files; do
target="$HOME/.config/$(basename "$config")"
backup_target_if_present "$target"
done
bin_files=$(find "$DOTFILES/local/bin" -mindepth 1 -maxdepth 1 2>/dev/null)
for bin in $bin_files; do
target="$HOME/.local/bin/$(basename "$bin")"
backup_target_if_present "$target"
done
}
setup_symlinks() {
title "Creating symlinks"
info "Force-linking; assumes backup already happened"
for file in $(get_linkables) ; do
target="$HOME/$(basename "$file" '.symlink')"
force_link "$file" "$target"
done
echo -e
info "installing to ~/.config"
if [ ! -d "$HOME/.config" ]; then
info "Creating ~/.config"
mkdir -p "$HOME/.config"
fi
config_files=$(find "$DOTFILES/config" -mindepth 1 -maxdepth 1 2>/dev/null)
for config in $config_files; do
target="$HOME/.config/$(basename "$config")"
force_link "$config" "$target"
done
bin_files=$(find "$DOTFILES/local/bin" -mindepth 1 -maxdepth 1 2>/dev/null)
info "installing to ~/.local/bin"
if [ ! -d "$HOME/.local/bin" ]; then
info "Creating ~/.local/bin"
mkdir -p "$HOME/.local/bin"
fi
for bin in $bin_files; do
target="$HOME/.local/bin/$(basename "$bin")"
force_link "$bin" "$target"
done
}
setup_mise() {
title "Setting up mise"
export PATH="${HOME}/.local/bin:${PATH:-}"
if ! command -v mise >/dev/null 2>&1; then
info "mise not installed. Installing."
curl -fsSL https://mise.run | MISE_QUIET=1 sh
export PATH="${HOME}/.local/bin:${PATH}"
success "mise installed"
fi
# Activate mise shims so tools are available in this shell
if command -v mise >/dev/null 2>&1; then
if eval "$(mise activate bash --shims)" 2>/dev/null; then
info "mise shims activated for this shell"
else
warning "Failed to activate mise shims; tools may not be on PATH in this shell"
fi
fi
info "Installing tools from config/mise/config.toml"
mise install
success "mise tools installed"
# only run these steps in GitHub Codespaces
if [[ "${CODESPACES:-}" == "true" ]]; then
mise use -g opencode
mise use -g npm:@fission-ai/openspec
fi
}
function install_neovim_plugins() {
title "Installing neovim plugins"
info "Installing neovim plugins"
nvim --headless "+Lazy! sync" +qa
success "neovim plugins installed"
}
function install_tmux_plugins() {
title "Installing tmux plugins"
info "Installing tmux plugin manager"
git clone --depth=1 https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm
success "tmux plugin manager installed"
info "Installing tmux plugins"
~/.tmux/plugins/tpm/bin/install_plugins
success "tmux plugins installed"
}
function install_uv_tools() {
title "Installing Python CLI tools (uv)"
info "Installing Python CLI tools (uv)"
bash "$DOTFILES/install_uv_tools.sh"
success "uv tools installed"
}
function setup_terminfo() {
title "Configuring terminfo"
info "adding tmux.terminfo"
tic -x "$DOTFILES/resources/tmux.terminfo"
success "tmux.terminfo installed"
info "adding xterm-256color-italic.terminfo"
tic -x "$DOTFILES/resources/xterm-256color-italic.terminfo"
success "xterm-256color-italic.terminfo installed"
}
function install_all_packages() {
install_uv_tools
install_tmux_plugins
# install_neovim_plugins
}
case "$1" in
backup)
backup
;;
link)
setup_symlinks
;;
terminfo)
setup_terminfo
;;
all)
backup
setup_symlinks
setup_terminfo
setup_mise
install_all_packages
;;
*)
# Default: symlinks, terminfo, mise, then extra packages
backup
setup_symlinks
setup_terminfo
setup_mise
install_all_packages
;;
esac
echo -e
success "Done."