Files
shell/install/nerd-fonts
T
2026-07-10 15:11:51 +08:00

81 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
##makedesc: Install nerd-fonts
set -eo pipefail
#TODO nokia-sans
installed() { command -v "$1" >/dev/null 2>&1; }
isMac() { [ "$(uname -s)" = "Darwin" ]; }
isLinux() { [ "$(uname -s)" = "Linux" ]; }
url="https://github.com/ryanoasis/nerd-fonts/releases/latest/download"
downloadPath="$HOME/install/nerd-fonts"
if isMac; then
installPath="$HOME/Library/Fonts/"
elif isLinux; then
installPath="$HOME/.local/share/fonts/"
else
echo "This OS is not supported yet!"
exit
fi
fontsNames=(
FiraCode
# FiraMono
JetBrainsMono
Meslo
# Noto
RobotoMono
# Ubuntu
# UbuntuMono
# UbuntuSans
)
install() {
echo
echo "==============================================="
echo "Installing nerd-fonts"
echo "==============================================="
echo
[[ -d "$downloadPath" ]] || mkdir -p "$downloadPath"
for fontname in "${fontsNames[@]}"; do
fontDir="$installPath/Nerd-$fontname"
if installed wget; then
wget -q --show-progress "$url/$fontname.tar.xz" -O "$downloadPath/$fontname.tar.xz"
else
curl -fsSL "$url/$fontname.tar.xz" -o "$downloadPath/$fontname.tar.xz"
fi
[[ -d "$installPath/$fontname" ]] || mkdir -p "$fontDir"
tar -xJf "$downloadPath/$fontname.tar.xz" -C "$fontDir"
done
isLinux && fc-cache -vf "$installPath"
echo
echo "Finish!"
echo
}
remove() {
echo
echo "==============================================="
echo "Removing nerd-fonts"
echo "==============================================="
echo
find "$installPath" -type d -name "Nerd-*" -exec rm -rf {} +
isLinux && fc-cache -vf "$installPath"
echo
echo "Finish!"
echo
}
case "$1" in
r|remove|d|delete|p|purge) remove ;;
*) install ;;
esac