-
Notifications
You must be signed in to change notification settings - Fork 1
/
install-exa.sh
executable file
·59 lines (48 loc) · 1.58 KB
/
install-exa.sh
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
#!/bin/bash
BOLD="$(tput bold 2>/dev/null || printf '')"
GREY="$(tput setaf 0 2>/dev/null || printf '')"
UNDERLINE="$(tput smul 2>/dev/null || printf '')"
RED="$(tput setaf 1 2>/dev/null || printf '')"
GREEN="$(tput setaf 2 2>/dev/null || printf '')"
YELLOW="$(tput setaf 3 2>/dev/null || printf '')"
BLUE="$(tput setaf 4 2>/dev/null || printf '')"
MAGENTA="$(tput setaf 5 2>/dev/null || printf '')"
NO_COLOR="$(tput sgr0 2>/dev/null || printf '')"
pinfo() {
printf '%s\n' "${BOLD}${GREY}>${NO_COLOR} $*"
}
pwarn() {
printf '%s\n' "${YELLOW}! $*${NO_COLOR}"
}
perror() {
printf '%s\n' "${RED}x $*${NO_COLOR}" >&2
}
pcompleted() {
printf '%s\n' "${GREEN}✓${NO_COLOR} $*"
}
TARGET_DIR="$HOME/.local/"
BIN_DIR="${TARGET_DIR}/bin"
# mkdir -p "$BIN_DIR"
if [ -f "$BIN_DIR/exa" ]; then
perror "$BIN_DIR/exa already exists, delete to reinstall"
exit
fi
pinfo "Installing exa, OS: ${OS}, ARCH: ${ARCH}, TMPDIR: ${UNDERLINE}${TMPDIR}${NO_COLOR}"
TMPDIR="$(mktemp -d -t install-exa.XXXXXX)"
(
set -e
trap 'perror $LINENO' ERR
cd "$TMPDIR" || {
perror "Failed to cd to $TMPDIR"
exit 1
}
OS="$(uname | tr '[:upper:]' '[:lower:]')"
ARCH="$(uname -m)"
VERSION="$(curl -sL "https://api.github.com/repos/ogham/exa/releases/latest" | jq -r '.tag_name')"
TARGET="exa-${OS}-${ARCH}-${VERSION}.zip"
curl -sLO "https://github.com/ogham/exa/releases/download/${VERSION}/${TARGET}"
unzip "$TARGET" -d "$TARGET_DIR"
mv "${TARGET_DIR}/completions/exa.zsh" "${TARGET_DIR}/completions/_exa"
pcompleted "Succesfully installed ${UNDERLINE}${BIN_DIR}/exa${NO_COLOR}"
)
rm -rf "$TMPDIR"