feat: fonts module (#52)
* feat: nerd-fonts modules * feat: nerd-fonts modules * feat: fonts module * fix: fonts module readme * chore: fonts module readme * chore: fonts module * chore: fonts module * Update nerd-fonts.sh * Update google-fonts.sh * chore: scripts * docs: unify font module grammar with other modules fixes some misc grammar mistakes and makes documentation more inline with that of other modules * refactor: move download.sh to root directory this removes the need of the font source scripts to have an environment variable with path to the ./scripts directory making them more portable * fix: get correct download.sh path (relative to currently running script) * chore: rm loop making .sh in scripts/ executable this is not needed, as download.sh was moved and is called with bash --------- Co-authored-by: xyny <60004820+xynydev@users.noreply.github.com>
This commit is contained in:
parent
8b1f2f2baf
commit
53507920aa
5 changed files with 129 additions and 0 deletions
20
modules/fonts/README.md
Normal file
20
modules/fonts/README.md
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
# `fonts` module for startingpoint
|
||||
|
||||
The `fonts` module can be used to install [nerd-fonts](https://www.nerdfonts.com/) or [google-fonts](https://fonts.google.com/). This module will always download the latest version and properly configure fonts.
|
||||
|
||||
## Example configuration
|
||||
|
||||
```yaml
|
||||
- type: fonts
|
||||
fonts:
|
||||
nerd-fonts:
|
||||
- FiraCode # don't add "Nerd Font" suffix.
|
||||
- Hack
|
||||
- SourceCodePro
|
||||
- Terminus
|
||||
- JetBrainsMono
|
||||
- NerdFontsSymbolsOnly
|
||||
google-fonts:
|
||||
- Roboto
|
||||
- Open Sans
|
||||
```
|
||||
39
modules/fonts/download.sh
Normal file
39
modules/fonts/download.sh
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#!/usr/bin/env bash
|
||||
set -oue pipefail
|
||||
|
||||
NAME=$1
|
||||
FORMAT=$2
|
||||
URL=$3
|
||||
DEST=$4
|
||||
|
||||
mkdir -p "$DEST"
|
||||
|
||||
DOWNLOAD=$(ls "$DEST" | wc -l)
|
||||
FILE="$NAME.$FORMAT"
|
||||
|
||||
if [[ $DOWNLOAD -eq 0 ]]; then
|
||||
|
||||
echo "Downloading $FILE"
|
||||
|
||||
curl -o "$FILE" -OL "$URL"
|
||||
|
||||
if [[ -f "$FILE" ]]; then
|
||||
|
||||
case $FORMAT in
|
||||
|
||||
tar.xz) tar xvJf "$FILE" -C "$DEST" ;;
|
||||
zip) unzip "$FILE" -d "$DEST" ;;
|
||||
|
||||
esac
|
||||
|
||||
rm -rf "$FILE"
|
||||
|
||||
echo "$FILE downloaded"
|
||||
|
||||
else
|
||||
|
||||
echo "Unable to download $FILE"
|
||||
|
||||
fi
|
||||
|
||||
fi
|
||||
16
modules/fonts/fonts.sh
Normal file
16
modules/fonts/fonts.sh
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#!/usr/bin/env bash
|
||||
set -oue pipefail
|
||||
|
||||
export FONTS_MODULE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
|
||||
|
||||
for source in "$FONTS_MODULE_DIR"/sources/*.sh; do
|
||||
|
||||
chmod +x "$source"
|
||||
|
||||
filename=$(basename -- "$source")
|
||||
|
||||
get_yaml_array FONTS ".fonts.${filename%.*}[]" "$1"
|
||||
|
||||
bash "$source" "${FONTS[@]}"
|
||||
|
||||
done
|
||||
27
modules/fonts/sources/google-fonts.sh
Normal file
27
modules/fonts/sources/google-fonts.sh
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#!/usr/bin/env bash
|
||||
set -oue pipefail
|
||||
|
||||
mapfile -t FONTS <<< "$@"
|
||||
URL="https://fonts.google.com/download?family="
|
||||
DIR_PRINCIPAL=/usr/share/fonts/google-fonts
|
||||
COMPACT_FORMAT="zip"
|
||||
|
||||
# To download google-fonts it is necessary to enter the name of the font replacing the spaces with '%20'. See the 3rd parameter of the download script.
|
||||
|
||||
if [ ${#FONTS[@]} -gt 0 ]; then
|
||||
|
||||
echo "Installation of google-fonts started"
|
||||
|
||||
rm -rf "$DIR_PRINCIPAL"
|
||||
|
||||
for font in "${FONTS[@]}"; do
|
||||
|
||||
font="$(echo "$font" | sed -e 's|^[[:blank:]]||g' | tr -d '\n')"
|
||||
|
||||
bash "$(dirname "$0")"/../download.sh "$font" "$COMPACT_FORMAT" "$URL${font// /%20}" "$DIR_PRINCIPAL/$font"
|
||||
|
||||
done
|
||||
|
||||
fc-cache -f $DIR_PRINCIPAL
|
||||
|
||||
fi
|
||||
27
modules/fonts/sources/nerd-fonts.sh
Normal file
27
modules/fonts/sources/nerd-fonts.sh
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#!/usr/bin/env bash
|
||||
set -oue pipefail
|
||||
|
||||
mapfile -t FONTS <<< "$@"
|
||||
URL="https://github.com/ryanoasis/nerd-fonts/releases/latest/download/"
|
||||
DIR_PRINCIPAL=/usr/share/fonts/nerd-fonts
|
||||
COMPACT_FORMAT="zip"
|
||||
|
||||
# To download nerd-fonts you need to enter the name of the font and the format you want. See the 3rd parameter of the download script.
|
||||
|
||||
if [ ${#FONTS[@]} -gt 0 ]; then
|
||||
|
||||
echo "Installation of nerd-fonts started"
|
||||
|
||||
rm -rf "$DIR_PRINCIPAL"
|
||||
|
||||
for font in "${FONTS[@]}"; do
|
||||
|
||||
font="$(echo "$font" | sed -e 's|^[[:blank:]]||g' | tr -d '\n')"
|
||||
|
||||
bash "$(dirname "$0")"/../download.sh "$font" "$COMPACT_FORMAT" "$URL$font.$COMPACT_FORMAT" "$DIR_PRINCIPAL/$font"
|
||||
|
||||
done
|
||||
|
||||
fc-cache -f $DIR_PRINCIPAL
|
||||
|
||||
fi
|
||||
Loading…
Add table
Add a link
Reference in a new issue