Last active
June 20, 2024 19:00
-
-
Save itsmikita/b96bbbbf2c6e089dce387cc57ca40192 to your computer and use it in GitHub Desktop.
(Arch) Linux CLI to install multiple fonts simultaneously
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Function to display usage | |
usage() { | |
echo "Usage: $0 [-s] <file_or_directory_path>..." | |
echo " -s Install fonts system-wide (requires sudo)" | |
exit 1 | |
} | |
# Function to install fonts and update font cache | |
install_fonts() { | |
for path in "$@"; do | |
if [ -d "$path" ]; then | |
find "$path" -type f \( -iname "*.otf" -o -iname "*.ttf" \) -exec cp {} "$FONT_DIR" \; | |
elif [ -f "$path" ] && [[ "$path" =~ \.(otf|ttf)$ ]]; then | |
cp "$path" "$FONT_DIR" | |
else | |
echo "Skipping invalid path: $path" | |
fi | |
done | |
fc-cache -fv | |
echo "Fonts installed successfully." | |
} | |
# Check if at least one argument is provided | |
if [ $# -lt 1 ]; then | |
usage | |
fi | |
# Parse options | |
SYSTEM_WIDE=0 | |
while getopts "s" opt; do | |
case ${opt} in | |
s ) | |
SYSTEM_WIDE=1 | |
;; | |
\? ) | |
usage | |
;; | |
esac | |
done | |
shift $((OPTIND -1)) | |
# Determine the destination directory | |
if [ $SYSTEM_WIDE -eq 1 ]; then | |
FONT_DIR="/usr/share/fonts" | |
if [ "$EUID" -ne 0 ]; then | |
echo "System-wide installation requires sudo privileges." | |
sudo echo "Sudo privileges granted." | |
fi | |
sudo install_fonts "$@" | |
else | |
FONT_DIR="$HOME/.local/share/fonts" | |
mkdir -p "$FONT_DIR" | |
install_fonts "$@" | |
fi | |
# Install fonts and update font cache | |
if [ $SYSTEM_WIDE -eq 1 ]; then | |
sudo install_fonts "$@" | |
else | |
install_fonts "$@" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment