diff --git a/README.md b/README.md index c5dbf11..5778638 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,7 @@ There is also a script that automates the deletion of all Monaspace fonts from ` ```bash $ cd util -$ bash ./install_macos.sh +$ bash ./install.sh ``` You can also use [homebrew](https://brew.sh/) as an alternative: @@ -68,7 +68,7 @@ There is also a script which automates the deletion of all Monaspace fonts from ```bash $ cd util -$ bash ./install_linux.sh +$ bash ./install.sh ``` ### Webfonts diff --git a/util/install.sh b/util/install.sh new file mode 100644 index 0000000..7f44635 --- /dev/null +++ b/util/install.sh @@ -0,0 +1,66 @@ +#!/bin/bash + +echo "Starting font installation process..." + +# Get target root directory +if [[ $(uname) == 'Darwin' ]]; then + # MacOS + sys_share_dir="/Library" + usr_share_dir="$HOME/Library" + font_subdir="Fonts" + echo "Detected MacOS. Setting directories accordingly." +else + # Linux + sys_share_dir="/usr/local/share" + usr_share_dir="$HOME/.local/share" + font_subdir="fonts" + echo "Detected Linux. Setting directories accordingly." +fi +if [ -n "${XDG_DATA_HOME}" ]; then + usr_share_dir="${XDG_DATA_HOME}" + echo "Using XDG_DATA_HOME as the user share directory." +fi + +# Function to delete and copy fonts for macOS +install_fonts_mac() { + echo "Removing existing Monaspace fonts from ${usr_share_dir}/${font_subdir}..." + rm -rf ${usr_share_dir}/${font_subdir}/Monaspace* + + echo "Copying new fonts to ${usr_share_dir}/${font_subdir}..." + cp ../fonts/otf/* ${usr_share_dir}/${font_subdir} + cp ../fonts/variable/* ${usr_share_dir}/${font_subdir} + + echo "Fonts successfully installed for MacOS." +} + +# Function to delete and copy fonts for Linux +install_fonts_linux() { + echo "Ensuring font directory exists at ${usr_share_dir}/${font_subdir}..." + mkdir -p ${usr_share_dir}/${font_subdir} + + echo "Removing existing Monaspace fonts from ${usr_share_dir}/${font_subdir}..." + rm -rf ${usr_share_dir}/${font_subdir}/Monaspace* + + echo "Copying new fonts..." + SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) + cp $SCRIPT_DIR/../fonts/otf/* ${usr_share_dir}/${font_subdir} + cp $SCRIPT_DIR/../fonts/variable/* ${usr_share_dir}/${font_subdir} + + echo "Rebuilding font information caches..." + fc-cache -f + + echo "Fonts successfully installed for Linux." +} + +# Detect the operating system and install fonts +OS="$(uname)" +if [ "$OS" == "Darwin" ]; then + install_fonts_mac +elif [ "$OS" == "Linux" ]; then + install_fonts_linux +else + echo "Unsupported operating system: $OS" + exit 1 +fi + +echo "Font installation process completed." diff --git a/util/install_linux.sh b/util/install_linux.sh deleted file mode 100755 index be4569d..0000000 --- a/util/install_linux.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -# remove all fonts from ~/.local/share/fonts that start with "Monaspace" -rm -rf ~/.local/share/fonts/Monaspace* - -# copy all fonts from ./otf to ~/.local/share/fonts -cp ./fonts/otf/* ~/.local/share/fonts - -# copy variable fonts from ./variable to ~/.local/share/fonts -cp ./fonts/variable/* ~/.local/share/fonts - -# Build font information caches -fc-cache -f diff --git a/util/install_macos.sh b/util/install_macos.sh deleted file mode 100644 index 5ccc20b..0000000 --- a/util/install_macos.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -# remove all fonts from ~/Library/Fonts that start with "Monaspace" -rm -rf ~/Library/Fonts/Monaspace* - -# copy all fonts from ./otf to ~/Library/Fonts -cp ../fonts/otf/* ~/Library/Fonts - -# copy variable fonts from ./variable to ~/Library/Fonts -cp ../fonts/variable/* ~/Library/Fonts \ No newline at end of file