-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.sh
More file actions
executable file
·54 lines (44 loc) · 1.79 KB
/
Copy pathbootstrap.sh
File metadata and controls
executable file
·54 lines (44 loc) · 1.79 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
#!/bin/sh
# Bootstrap script for Zert - clones the zert repository
# This script is POSIX sh compatible (no zsh dependencies)
#
# Add this to your .zshrc:
# export ZERT_PLUGINS_DIR="${ZERT_PLUGINS_DIR:-${ZERT_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/zert}/plugins}"; \
# [[ -f "$ZERT_PLUGINS_DIR/zert/zert.zsh" ]] || \
# (curl -fsSL https://raw.githubusercontent.com/oxcl/zert/main/bootstrap.sh | zsh); \
# source "$ZERT_PLUGINS_DIR/zert/zert.zsh"
#
# zert zert # manage zert itself (optional, enables self-updates)
set -e
# Check for git
command -v git >/dev/null 2>&1 || {
printf '[zert] git is required but not found.\n' >&2
exit 1
}
# Determine ZERT_PLUGINS_DIR with XDG defaults
export ZERT_PLUGINS_DIR="${ZERT_PLUGINS_DIR:-${ZERT_DIR:-${XDG_DATA_HOME:-$HOME/.local/share}/zert}/plugins}"
# If already cloned (marker files exist), we're done (idempotent)
if [ -f "$ZERT_PLUGINS_DIR/zert/zert.zsh" ] && [ -f "$ZERT_PLUGINS_DIR/zert/zert.plugin.zsh" ]; then
exit 0
fi
# Create directory if needed
mkdir -p "$ZERT_PLUGINS_DIR"
# Clone to temp directory first, then move (atomic-ish)
TMPDIR_ZERT=$(mktemp -d "$ZERT_PLUGINS_DIR/.zert-bootstrap-XXXXXX")
cleanup() {
rm -rf "$TMPDIR_ZERT"
}
trap cleanup EXIT
# Log message (respects NO_COLOR)
if [ -z "$NO_COLOR" ]; then
printf '\033[36m[zert] Downloading zert to %s/zert...\033[0m\n' "$ZERT_PLUGINS_DIR" >&2
else
printf '[zert] Downloading zert to %s/zert...\n' "$ZERT_PLUGINS_DIR" >&2
fi
# Clone zert repository (shallow, single-branch for minimal bandwidth, silent unless error)
if ! git clone --quiet --single-branch --branch main --depth 1 https://github.com/oxcl/zert.git "$TMPDIR_ZERT/zert" 2>&1; then
printf '[zert] Failed to clone zert repository.\n' >&2
exit 1
fi
# Move to final location
mv "$TMPDIR_ZERT/zert" "$ZERT_PLUGINS_DIR/zert"