diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..372bb83 --- /dev/null +++ b/Makefile @@ -0,0 +1,71 @@ +#!/usr/bin/env make + +FONT_FAMILY := Monaspace +RELEASE_DIR := fonts +VARIANTS := otf variable webfonts +EXCLUDES := webfonts + +ifeq ($(OS),Windows_NT) +DEST_DIR := $(shell powershell (Get-Item Env:WINDIR).Value)\Fonts +INSTALL := xcopy /Y /I +MKDIR := mkdir +RM := del /Q + +POST_INSTALL = $(foreach font,$(notdir $(INSTALL_FONT_TARGETS)), \ + powershell reg add \"HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts\" /v \"$(font) (TrueType)\" /t REG_SZ /d $(font) /f >NUL & \ +) +POST_UNINSTALL = $(foreach font,$(notdir $(INSTALL_FONT_TARGETS)), \ + powershell reg delete \"HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts\" /v \"$(font) (TrueType)\" /f >NUL & \ +) + +sep := \\# +else +uname_s := $(shell uname -s) +ifeq ($(uname_s),Darwin) +DEST_DIR := $(HOME)/Library/Fonts +else +DEST_DIR := $(or $(XDG_DATA_HOME),$(HOME)/.local/share)/fonts +POST_INSTALL := /usr/bin/env fc-cache -f +WRAP := 1 +endif + +INSTALL := /usr/bin/env install -m 644 +MKDIR := /usr/bin/env mkdir -p +RM := /usr/bin/env rm -f + +POST_UNINSTALL = $(ifeq $(WRAP),1,$(shell rmdir $(install_path) 2>/dev/null)) + +sep := / +endif + +install_path := $(DEST_DIR)$(if $(filter $(WRAP),1),$(sep)$(FONT_FAMILY),) + +RELEASE_FONTS := $(wildcard $(RELEASE_DIR)/**/*) +INSTALL_FONTS := $(filter-out \ + $(foreach exclude,$(EXCLUDES),$(wildcard $(RELEASE_DIR)/$(exclude)/*)), \ + $(RELEASE_FONTS) \ +) +INSTALL_FONT_TARGETS := $(addprefix $(install_path)$(sep),$(notdir $(INSTALL_FONTS))) + +.PHONY: install +install: $(INSTALL_FONT_TARGETS) + @$(POST_INSTALL) + @echo Fonts successfully installed in $(install_path) + +.PHONY: uninstall +uninstall: + @$(RM) $(install_path)$(sep)$(FONT_FAMILY)* + @$(POST_UNINSTALL) + @echo Fonts successfully uninstalled + +$(install_path): + @$(MKDIR) $@ + +define install_font_target +$(install_path)$(if $(filter $(OS),Windows_NT),\,)$(sep)%: $(RELEASE_DIR)$(sep)$(1)$(sep)% | $(install_path) + @$(INSTALL) $$< $(install_path) +endef + +$(foreach variant,$(filter-out $(EXCLUDES),$(VARIANTS)), \ + $(eval $(call install_font_target,$(variant))) \ +) \ No newline at end of file diff --git a/README.md b/README.md index b0194f3..c81f2e2 100644 --- a/README.md +++ b/README.md @@ -42,33 +42,44 @@ You must enable discretionary ligatures first, often using the `dlig` setting. S ## Desktop Installation -### MacOS -You can manually drag the fonts from the `fonts/otf` or `fonts/variable` directory into Font Book. +### Manually -There is also a script that automates the deletion of all Monaspace fonts from `~/Library/Fonts` and then copies over the latest versions. Invoke it from the root of the repo like: +Use the provided [`Makefile`](Makefile) targets: -```bash -$ cd util -$ bash ./install_macos.sh +```sh +$ make install +Fonts successfully installed in ~/.local/share/fonts/Monaspace ``` -You can also use [homebrew](https://brew.sh/) as an alternative: -```bash -brew tap homebrew/cask-fonts -brew install font-monaspace +```sh +$ make uninstall +Fonts successfully uninstalled +``` + +#### Make Optional flags + +| name | description | default value | +|-|-|-| +| DEST_DIR | Base directory where the fonts should be installed. | Windows: `%WINDIR%/Fonts`
MacOS: `~/Library/Fonts`
Linux: `~/.local/share/fonts` | +| WRAP | Install the fonts in a subfolder named `Monaspace` within the `DEST_DIR`
`1` to enable, unset or any other value to disable it.| Enable by default for Linux which is the only one that supports it. | + +**Examples:** +```sh +$ make install DEST_DIR=~/.fonts +``` +```sh +$ make install WRAP=no ``` -### Windows -You can manually drag the fonts from the `fonts/otf` or `fonts/variable` directory into `C:\Windows\Fonts`. Alternatively, right-click the fonts you want and click Install. +### Package managers -### Linux -You can manually drag the fonts from the `fonts/otf` and `fonts/variable` directory into `~/.local/share/fonts`. +#### MacOS -There is also a script which automates the deletion of all Monaspace fonts from `~/.local/share/fonts` and then copies over the latest versions. Invoke it from the root of the repo like: +A [homebrew](https://brew.sh/) cask is available for MacOS: ```bash -$ cd util -$ bash ./install_linux.sh +$ brew tap homebrew/cask-fonts +$ brew install font-monaspace ``` ### Webfonts 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