-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·98 lines (81 loc) · 2.87 KB
/
install.sh
File metadata and controls
executable file
·98 lines (81 loc) · 2.87 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
#!/bin/sh
set -eu
REPO="sounak98/betterstack-cli"
INSTALL_DIR="${BS_INSTALL_DIR:-$HOME/.local/bin}"
main() {
os=$(uname -s | tr '[:upper:]' '[:lower:]')
arch=$(uname -m)
case "$os" in
linux) os="unknown-linux-gnu" ;;
darwin) os="apple-darwin" ;;
*) echo "Unsupported OS: $os" >&2; exit 1 ;;
esac
case "$arch" in
x86_64|amd64) arch="x86_64" ;;
aarch64|arm64) arch="aarch64" ;;
*) echo "Unsupported architecture: $arch" >&2; exit 1 ;;
esac
target="${arch}-${os}"
if [ -n "${BS_VERSION:-}" ]; then
tag="v$BS_VERSION"
else
tag=$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" | grep '"tag_name"' | sed 's/.*"tag_name": *"//;s/".*//')
if [ -z "$tag" ]; then
echo "Failed to fetch latest release" >&2
exit 1
fi
fi
url="https://github.com/$REPO/releases/download/$tag/bs-$target.tar.gz"
echo "Installing bs $tag ($target)"
echo " from: $url"
echo " to: $INSTALL_DIR/bs"
echo
tmp=$(mktemp -d)
trap 'rm -rf "$tmp"' EXIT
curl -fsSL "$url" -o "$tmp/bs.tar.gz"
tar xzf "$tmp/bs.tar.gz" -C "$tmp"
mkdir -p "$INSTALL_DIR"
mv "$tmp/bs" "$INSTALL_DIR/bs"
chmod +x "$INSTALL_DIR/bs"
echo "Installed bs $tag successfully!"
echo
if ! echo "$PATH" | tr ':' '\n' | grep -qx "$INSTALL_DIR"; then
echo "Add $INSTALL_DIR to your PATH:"
echo " export PATH=\"$INSTALL_DIR:\$PATH\""
echo
fi
install_completions
}
install_completions() {
shell_name=$(basename "${SHELL:-}")
case "$shell_name" in
bash)
comp_dir="${BASH_COMPLETION_USER_DIR:-$HOME/.local/share/bash-completion/completions}"
mkdir -p "$comp_dir"
"$INSTALL_DIR/bs" completions bash > "$comp_dir/bs"
echo "Installed bash completions to $comp_dir/bs"
;;
zsh)
comp_dir="${HOME}/.zfunc"
mkdir -p "$comp_dir"
"$INSTALL_DIR/bs" completions zsh > "$comp_dir/_bs"
echo "Installed zsh completions to $comp_dir/_bs"
zshrc="${ZDOTDIR:-$HOME}/.zshrc"
if ! grep -q 'fpath.*\.zfunc' "$zshrc" 2>/dev/null; then
printf '\n# bs CLI completions\nfpath=(~/.zfunc $fpath)\nautoload -Uz compinit && compinit\n' >> "$zshrc"
echo "Updated $zshrc with fpath and compinit"
fi
echo "Restart your shell or run: source $zshrc"
;;
fish)
comp_dir="${HOME}/.config/fish/completions"
mkdir -p "$comp_dir"
"$INSTALL_DIR/bs" completions fish > "$comp_dir/bs.fish"
echo "Installed fish completions to $comp_dir/bs.fish"
;;
*)
echo "Shell completions available via: bs completions <bash|zsh|fish|powershell|elvish>"
;;
esac
}
main