Created
February 12, 2023 13:25
-
-
Save Logic-gate/3abb7bb5130ed8e53ed65bdd6598c180 to your computer and use it in GitHub Desktop.
fontconfig helper script SailfishOS
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 | |
#Fontconfig helper script | |
#Use absolute path | |
common_aliases_dir=/home/defaultuser/.local/share/fonts/common-aliases | |
#common_extra_dir=/home/defaultuser/.local/share/fonts/common-extra | |
#lowdpi_aliases_dir=/home/defaultuser/.local/share/fonts/lowdpi-aliases | |
#lowdpi_extra_dir=/home/defaultuser/.local/share/fonts/lowdpi-extra | |
sfos_conf=/home/defaultuser/.config/fontconfig/os/sfos.conf | |
hyp="-" | |
LIST_FONT_DIR () { | |
### Takes a dir as $1 and prints everything after $2 | |
for font_dir in $1/* | |
do | |
echo "${font_dir#*$2}" | |
done | |
} | |
LIST_FONTS () { | |
### Takes a dir as $1 and finds everying ending with $2 | |
find $1 -type f -name "*.$2" | while read font | |
do | |
echo "${font#*$3}"; # Do something else | |
done | |
} | |
APPLY_FONT () { | |
### Replace current font with $1 given sfos.conf passed as var $2 | |
echo $1 | |
if [[ "$1" =~ ^[a-zA-Z-]*$ ]]; then | |
font_family="${1//-/ }" | |
else | |
font_family=$1 | |
fi | |
sed -i ':a;N;$!ba; s|<prefer>.*<\/prefer>|<prefer>\n\t\t<family>'"$font_family"'</family>\n\t</prefer>|g' $2 | |
} | |
for arg in "$@" | |
do | |
if [ "$arg" == "-l" ] | |
then | |
LIST_FONT_DIR $common_aliases_dir "common-aliases/" | |
elif [ "$arg" == "-lf" ] || [ "$arg" == "--list-fonts" ] | |
then | |
LIST_FONTS $common_aliases_dir $2 "common-aliases/" | |
elif [ "$arg" == "-a" ] || [ "$arg" == "--apply-font" ] | |
then | |
APPLY_FONT $2 $sfos_conf | |
cat $sfos_conf | |
elif [ "$arg" == "-r" ] || [ "$arg" == "--restart-lipstick" ] | |
then | |
systemctl --user restart lipstick | |
elif [ "$arg" == "-h" ] || [ "$arg" == "--help" ] | |
then | |
echo "" | |
echo "fontconfig SFOS Helper" | |
echo "Set Font in $common_aliases_dir" | |
echo "" | |
echo '''$1 [OPTION] <arg> | |
Options: | |
-l Lists available fonts dirs in common-aliases | |
-lf, --list-fonts Lists all font files ending with arg | |
-a, --apply-font Applies font in sfos.conf | |
-r, --restart-lipstick Restart Lipstick | |
-h, --help Print this message | |
--------------- | |
Usage: | |
-l --> will list all font dirs under common-aliases | |
-lf .ttf --> will list all ttf fonts that live in common-aliases | |
-a ReemKufiFun-Medium --> will append the prefer family value to "ReemKufiFun Medium" without the hyphen | |
-r --> will restart lisptick | |
''' | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment