Skip to content

Instantly share code, notes, and snippets.

@0x07CB
Created March 9, 2025 12:31
Show Gist options
  • Save 0x07CB/eade11ab3767ed18e7815c1cc6e379a8 to your computer and use it in GitHub Desktop.
Save 0x07CB/eade11ab3767ed18e7815c1cc6e379a8 to your computer and use it in GitHub Desktop.
This script install nerdfonts (from zip files in a predefined directory), into the system or the user home
#!/bin/bash
# AUTHOR: 0x07cb
# This script install the font into the system or the user home
# simple script with simple choice
# https://github.com/0x07cb
# buymeacoffee.com/0x07CB
echo -e "\e[32m\e[1mnerdfonts-install-script.sh\e[0m"
echo -e "Author: 0x07cb"
echo -e "--------------------------------"
echo -e "This script install the font into the system or the user home"
echo -e "--------------------------------"
echo -e "Github: https://github.com/0x07cb"
echo -e "Buy me a coffee: https://buymeacoffee.com/0x07CB"
echo -e "--------------------------------"
function is_root() {
if [ "$EUID" -ne 0 ]; then
echo -e "\e[31mPlease run as root\e[0m"
exit 1
fi
}
function install_font_into_system() {
is_root
sudo mkdir -p /usr/share/fonts/NerdFonts
if [ -d "nerdfonts" ]; then
for file in nerdfonts/*.zip; do
echo "unzip $file ..."
base_name=$(basename $file .zip)
unzip $file -d $base_name/
sudo cp $base_name/*.ttf /usr/share/fonts/NerdFonts/
sudo fc-cache -fv
rm -rf $base_name
fc-list | grep "$base_name" && echo -e "\e[32mFont installed\e[0m" || echo -e "\e[31mFont not installed\e[0m"
done
fi
}
function install_font_in_user_home() {
if [ "$EUID" -eq 0 ]; then
echo -e "\e[31mPlease run as user ! Not as root for this installation option\e[0m"
exit 1
fi
mkdir -p ~/.local/share/fonts/NerdFonts
if [ -d "nerdfonts" ]; then
for file in nerdfonts/*.zip; do
echo "unzip $file ..."
base_name=$(basename $file .zip)
unzip $file -d $base_name/
cp $base_name/*.ttf ~/.local/share/fonts/NerdFonts/
fc-cache -fv
rm -rf $base_name
fc-list | grep "$base_name" && echo -e "\e[32mFont installed\e[0m" || echo -e "\e[31mFont not installed\e[0m"
done
fi
}
function choose_installation_option() {
echo -e "\e[32mChoose the installation option:\e[0m"
echo "1. Install the font into the system"
echo "2. Install the font in the user home"
read -p "Enter the number of the installation option: " option
case $option in
1)
install_font_into_system
;;
2)
install_font_in_user_home
;;
*)
echo -e "\e[31mInvalid option\e[0m"
choose_installation_option
;;
esac
}
choose_installation_option
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment