forked from mcarvalho1/Simple-NerdFonts-Downloader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nf_downloader.sh
executable file
·222 lines (191 loc) · 4.99 KB
/
nf_downloader.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/bin/bash
declare distro extension font_choice version
declare -a fonts=(
0xProto
3270
Agave
AnonymousPro
Arimo
AurulentSansMono
BigBlueTerminal
BitstreamVeraSansMono
CascadiaCode
CascadiaMono
CodeNewRoman
ComicShannsMono
CommitMono
Cousine
D2Coding
DaddyTimeMono
DejaVuSansMono
DroidSansMono
EnvyCodeR
FantasqueSansMono
FiraCode
FiraMono
FontPatcher
GeistMono
Go-Mono
Gohu
Hack
Hasklig
HeavyData
Hermit
iA-Writer
IBMPlexMono
Inconsolata
InconsolataGo
InconsolataLGC
IntelOneMono
Iosevka
IosevkaTerm
IosevkaTermSlab
JetBrainsMono
Lekton
LiberationMono
Lilex
MartianMono
Meslo
Monaspace
Monofur
Monoid
Mononoki
MPlus
NerdFontsSymbolsOnly
Noto
OpenDyslexic
Overpass
ProFont
ProggyClean
RobotoMono
ShareTechMono
SourceCodePro
SpaceMono
Terminus
Tinos
Ubuntu
UbuntuMono
VictorMono
)
# Functions to install dependencies on different distros.
install_dependencies_debian() {
sudo apt-get update
sudo apt-get install -y wget unzip tar fontconfig
}
install_dependencies_fedora() {
sudo dnf install -y wget unzip tar fontconfig
}
install_dependencies_arch() {
sudo pacman -Sy --noconfirm wget unzip tar fontconfig
}
install_dependencies_osx() {
yes | brew install wget unzip gnu-tar fontconfig
status=$?
if [ $status -eq 1 ]; then exit 1; fi
}
install_dependencies() {
read -rp "Installing: wget, unzip, tar, fontconfig. Do you want to continue? (y/n): " install_dependency_choice
if [ "$install_dependency_choice" == "y" ]; then
case $distro in
"debian") install_dependencies_debian ;;
"fedora") install_dependencies_fedora ;;
"arch") install_dependencies_arch ;;
"osx") install_dependencies_osx ;;
*) echo "Unsupported distribution. Exiting."; exit 1 ;;
esac
else
echo "Exiting. Make sure to have the dependencies installed to continue."
exit 1
fi
}
# Functions to make selections
choose_distro() {
echo "Select your base distribution:"
echo "[1] - Debian/Ubuntu"
echo "[2] - Fedora"
echo "[3] - Arch: Linux"
echo "[4] - OSX"
read -rp "Enter the number of your base distribution: " distro_choice
case "$distro_choice" in
1) distro="debian";;
2) distro="fedora";;
3) distro="arch";;
4) distro="osx";;
*) echo "Invalid choice. Exiting."; exit 1 ;;
esac
}
choose_font() {
echo "Choose the font to install or select 'All' to download all fonts:"
for i in "${!fonts[@]}"; do
echo "[$((i+1))] - ${fonts[$i]}"
done
echo "[$((${#fonts[@]} + 1))] - All Fonts"
read -rp "Enter your choice: " font_choice
}
choose_extension() {
echo "Choose the extension to install:"
echo "[1] - .zip"
echo "[2] - .tar.xz"
read -rp "Enter the number of the desired extension: " extension_choice
if ! [[ "$extension_choice" =~ ^[1-2]$ ]]; then
echo "Invalid extension choice. Exiting."
exit 1
fi
case "$extension_choice" in
1) extension=".zip";;
2) extension=".tar.xz";;
esac
}
choose_version() {
latest_version=$(curl -s "https://api.github.com/repos/ryanoasis/nerd-fonts/tags" | jq -r '.[0].name')
echo "Choose version to install, enter a specific version using the vX.Y.Z format (latest version: $latest_version)"
read -rp "Enter your choice: " version
}
download_and_install_font() {
local selected_font="$1"
local extension="$2"
local version="$3"
local distro="$4"
local zip_file="${selected_font}${extension}"
local download_url="https://github.com/ryanoasis/nerd-fonts/releases/download/${version}/${zip_file}"
local font_dir=""
case $distro in
"osx") font_dir="/Library/Fonts";;
*)
font_dir="${HOME}/.local/share/fonts"
mkdir -p "$font_dir"
;;
esac
echo "Downloading and installing '$selected_font'..."
wget --quiet "$download_url" -O "$zip_file" || { echo "Error: Unable to download '$selected_font'."; return 1; }
if [[ "$extension" == ".zip" ]]; then
unzip -q "$zip_file" -d "$font_dir" || { echo "Error: Unable to extract '$selected_font'."; return 1; }
else
tar -xf "$zip_file" -C "$font_dir" || { echo "Error: Unable to extract '$selected_font'."; return 1; }
fi
rm "$zip_file"
echo "'$selected_font' installed successfully."
}
choose_distro
install_dependencies
choose_font
choose_extension
choose_version
if [ "$font_choice" -eq "$((${#fonts[@]} + 1))" ]; then
for font in "${fonts[@]}"; do
download_and_install_font "$font" "$extension" "$version" "$distro"
done
else
if ! [[ "$font_choice" =~ ^[1-9][0-9]*$ && "$font_choice" -le ${#fonts[@]} ]]; then
echo "Invalid font choice. Exiting."
exit 1
fi
selected_font="${fonts[$((font_choice-1))]}"
download_and_install_font "$selected_font" "$extension" "$version" "$distro"
fi
if command -v fc-cache &> /dev/null; then
fc-cache -f > /dev/null || { echo "Error: Unable to update font cache. Exiting."; exit 1; }
echo "Font cache updated."
else
echo "Command 'fc-cache' not found. Make sure to have the necessary dependencies installed to update the font cache."
fi