-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli_from_git.sh
87 lines (63 loc) · 2.53 KB
/
cli_from_git.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
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
#!/usr/bin/env bash
bindir="$HOME/opt/bin/"
reldir="$HOME/opt/.temp-cli-release"
findlatestversion() {
tempname=$(curl -Ls -o /dev/null -w "%{url_effective}" "$1")
echo "$tempname" | rev | cut -f 1 -d '/' | rev
}
getgitrelease() {
mkdir -p "${reldir}"
cd "${reldir}" || exit
mkdir contents
wget "$1" -q
tar_name=$(echo "$1" | rev | cut -f 1 -d '/' | rev)
tar xf "$tar_name" -C ./contents
exec_path=$(find ./contents -type f -name "$2")
mv "$exec_path" "$bindir"
rm "./contents" -rf
rm -rf "${reldir}"
}
check_and_download() {
if command -v "$1"; then
:
else
exec_name="$1"
download_link="$3"
version=$(findlatestversion "$2")
download_link=$(echo "$download_link" | sed -E "s#VERSION#${version}#g")
getgitrelease "$download_link" "$exec_name"
fi
}
check_and_download_no_v() {
if command -v "$1"; then
:
else
exec_name="$1"
download_link="$3"
version=$(findlatestversion "$2")
version="${version/v/}"
download_link=$(echo "$download_link" | sed -E "s#VERSION#${version}#g")
getgitrelease "$download_link" "$exec_name"
fi
}
just_download() {
if command -v "$1"; then
:
else
exec_name="$1"
download_link="$2"
getgitrelease "$download_link" "$exec_name"
fi
}
printf '\n##### fd #####\n'
check_and_download 'fd' 'https://github.com/sharkdp/fd/releases/latest/' 'https://github.com/sharkdp/fd/releases/latest/download/fd-VERSION-x86_64-unknown-linux-gnu.tar.gz'
printf '\n##### zellij #####\n'
just_download 'zellij' 'https://github.com/zellij-org/zellij/releases/latest/download/zellij-x86_64-unknown-linux-musl.tar.gz'
printf '\n##### eza #####\n'
just_download 'eza' "https://github.com/eza-community/eza/releases/latest/download/eza_x86_64-unknown-linux-gnu.tar.gz"
printf '\n##### ripgrep #####\n'
check_and_download 'rg' 'https://github.com/BurntSushi/ripgrep/releases/latest/' 'https://github.com/BurntSushi/ripgrep/releases/latest/download/ripgrep-VERSION-x86_64-unknown-linux-musl.tar.gz'
printf '\n##### lazygit #####\n'
check_and_download_no_v 'lazygit' 'https://github.com/jesseduffield/lazygit/releases/latest/' 'https://github.com/jesseduffield/lazygit/releases/latest/download/lazygit_VERSION_Linux_x86_64.tar.gz'
printg '\n##### numbat #####\n'
check_and_download 'numbat' 'https://github.com/sharkdp/numbat/releases/latest' 'https://github.com/sharkdp/numbat/releases/latest/download/numbat-VERSION-x86_64-unknown-linux-gnu.tar.gz'