-
Notifications
You must be signed in to change notification settings - Fork 170
/
use
51 lines (45 loc) · 1.25 KB
/
use
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
#!/bin/sh
# Usage:
#
# source <(curl https://raw.githubusercontent.com/k1LoW/tbls/main/use)
#
# Reference:
# https://github.com/goreleaser/get
TBLS_GOOS=linux
TBLS_EXT=tar.gz
TBLS_ARCH=amd64
if test $(uname -s) = "Darwin"
then
TBLS_GOOS=darwin
TBLS_EXT=zip
fi
TBLS_ARCHIVE="/tmp/tbls.${TBLS_EXT}"
TBLS_RELEASES_URL="https://github.com/k1LoW/tbls/releases"
test -z "${TBLS_TMPDIR:-}" && TBLS_TMPDIR="$(mktemp -d)"
last_version() {
curl -sL -o /dev/null -w %{url_effective} "$TBLS_RELEASES_URL/latest" |
rev |
cut -f1 -d'/'|
rev
}
download() {
test -z "${TBLS_VERSION:-}" && TBLS_VERSION="$(last_version)"
test -z "${TBLS_VERSION:-}" && {
echo "Unable to get tbls version." >&2
exit 1
}
# Skip downloading if the newest file was downloaded before
curl `if [ -f "$TBLS_ARCHIVE" ]; then echo -z "$TBLS_ARCHIVE"; fi` \
-s -L -o "$TBLS_ARCHIVE" \
"${TBLS_RELEASES_URL}/download/${TBLS_VERSION}/tbls_${TBLS_VERSION}_${TBLS_GOOS}_${TBLS_ARCH}.${TBLS_EXT}"
}
download
if test ${TBLS_EXT} = "tar.gz"
then
tar -xf "$TBLS_ARCHIVE" -C "$TBLS_TMPDIR"
elif test ${TBLS_EXT} = "zip"
then
unzip -qo "$TBLS_ARCHIVE" -d "$TBLS_TMPDIR"
fi
export PATH=${TBLS_TMPDIR}:$PATH
printf '\e[36mYou can use `tbls` command in this session.\e[m\n'