From f58ec1bfa4d23ffa34c6c0e5419debf115330967 Mon Sep 17 00:00:00 2001 From: Olivier Patry Date: Mon, 4 Nov 2024 09:25:43 +0100 Subject: [PATCH 1/5] Allow execution of util/install_*.sh from anywhere The original scripts were forcing the caller to be in the monospace directory and calling `./util/install_XXX.sh`. You can now execute `install_XXX.sh` from wherever you want. ex: `~/Downloads/monaspace-v1.101/util/install_macos.sh` --- util/install_linux.sh | 6 ++++-- util/install_macos.sh | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/util/install_linux.sh b/util/install_linux.sh index b1ece38f..e5ee2dc7 100755 --- a/util/install_linux.sh +++ b/util/install_linux.sh @@ -1,5 +1,7 @@ #!/bin/bash +origin=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) || exit + # ensure that ~/.local/share/fonts exists mkdir -p ~/.local/share/fonts @@ -9,10 +11,10 @@ rm -rf ~/.local/share/fonts/Monaspace* mkdir -p ~/.local/share/fonts/Monaspace/ # copy all fonts from ./otf to ~/.local/share/fonts -cp ./fonts/otf/* ~/.local/share/fonts/Monaspace/ +cp "${origin}/../fonts/otf/"* ~/.local/share/fonts/Monaspace/ # copy variable fonts from ./variable to ~/.local/share/fonts -cp ./fonts/variable/* ~/.local/share/fonts/Monaspace/ +cp "${origin}/../fonts/variable/"* ~/.local/share/fonts/Monaspace/ # Build font information caches fc-cache -f diff --git a/util/install_macos.sh b/util/install_macos.sh index ea0cced3..2ee65a0b 100755 --- a/util/install_macos.sh +++ b/util/install_macos.sh @@ -1,10 +1,12 @@ #!/bin/bash +origin=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) || exit + # 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 +cp "${origin}/../fonts/otf/"* ~/Library/Fonts # copy variable fonts from ./variable to ~/Library/Fonts -cp ./fonts/variable/* ~/Library/Fonts \ No newline at end of file +cp "${origin}/../fonts/variable/"* ~/Library/Fonts \ No newline at end of file From 97810e217ff662cbc23f045c0dcb91db2fbdd7f7 Mon Sep 17 00:00:00 2001 From: Olivier Patry Date: Mon, 4 Nov 2024 09:27:18 +0100 Subject: [PATCH 2/5] Use more portable bash shebang `#!/usr/bin/env` searches `PATH` for `bash`, and `bash` is not always in `/bin`, particularly on non-Linux systems. See https://en.wikipedia.org/wiki/Shebang_(Unix)#Portability --- util/install_linux.sh | 2 +- util/install_macos.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/util/install_linux.sh b/util/install_linux.sh index e5ee2dc7..3d202dbf 100755 --- a/util/install_linux.sh +++ b/util/install_linux.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash origin=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) || exit diff --git a/util/install_macos.sh b/util/install_macos.sh index 2ee65a0b..6f504b9b 100755 --- a/util/install_macos.sh +++ b/util/install_macos.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash origin=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) || exit From 2e1f0cb00aa55cf2090c3770e966bb80924f6ed4 Mon Sep 17 00:00:00 2001 From: Olivier Patry Date: Mon, 4 Nov 2024 09:27:40 +0100 Subject: [PATCH 3/5] Fail install scripts on error --- util/install_linux.sh | 2 ++ util/install_macos.sh | 2 ++ 2 files changed, 4 insertions(+) diff --git a/util/install_linux.sh b/util/install_linux.sh index 3d202dbf..ad155aa8 100755 --- a/util/install_linux.sh +++ b/util/install_linux.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +set -euo pipefail + origin=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) || exit # ensure that ~/.local/share/fonts exists diff --git a/util/install_macos.sh b/util/install_macos.sh index 6f504b9b..38ccc710 100755 --- a/util/install_macos.sh +++ b/util/install_macos.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +set -euo pipefail + origin=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) || exit # remove all fonts from ~/Library/Fonts that start with "Monaspace" From 7829bffadabb03892aca8c2d8f46590c844d0ebe Mon Sep 17 00:00:00 2001 From: Olivier Patry Date: Mon, 4 Nov 2024 09:39:15 +0100 Subject: [PATCH 4/5] Adjust README.md install instruction to reflect the more generic use of bash --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index bf364b68..208db1c3 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ You can manually drag the fonts from the `fonts/otf` or `fonts/variable` directo 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: ```bash -$ bash util/install_macos.sh +$ ./util/install_macos.sh ``` You can also use [homebrew](https://brew.sh/) as an alternative: @@ -99,7 +99,7 @@ You can manually drag the fonts from the `fonts/otf` and `fonts/variable` direct 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: ```bash -$ bash util/install_linux.sh +$ ./util/install_linux.sh ``` ### Webfonts From ddf438aa4f2c20d4cb3ff33326290c588be21388 Mon Sep 17 00:00:00 2001 From: Olivier Patry Date: Mon, 4 Nov 2024 09:41:45 +0100 Subject: [PATCH 5/5] Extract in/out variables for convenience in install scripts Would easily allow letting caller choose output dir for instance. ```bash fonts_dir="${1:-"${HOME}/Library/Fonts"}" ``` Note: Used `${HOME}` as a replacement of `~` which doesn't expands within quotes. See https://www.shellcheck.net/wiki/SC2088 --- util/install_linux.sh | 13 ++++++++----- util/install_macos.sh | 9 ++++++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/util/install_linux.sh b/util/install_linux.sh index ad155aa8..2f8f773d 100755 --- a/util/install_linux.sh +++ b/util/install_linux.sh @@ -4,19 +4,22 @@ set -euo pipefail origin=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) || exit +input_dir="${origin}/../fonts" +fonts_dir="${HOME}/.local/share/fonts" + # ensure that ~/.local/share/fonts exists -mkdir -p ~/.local/share/fonts +mkdir -p "${fonts_dir}" # remove all fonts from ~/.local/share/fonts that start with "Monaspace" -rm -rf ~/.local/share/fonts/Monaspace* +rm -rf "${fonts_dir}/"Monaspace* -mkdir -p ~/.local/share/fonts/Monaspace/ +mkdir -p "${fonts_dir}/Monaspace/" # copy all fonts from ./otf to ~/.local/share/fonts -cp "${origin}/../fonts/otf/"* ~/.local/share/fonts/Monaspace/ +cp "${input_dir}/otf/"* "${fonts_dir}/Monaspace/" # copy variable fonts from ./variable to ~/.local/share/fonts -cp "${origin}/../fonts/variable/"* ~/.local/share/fonts/Monaspace/ +cp "${input_dir}/variable/"* "${fonts_dir}/Monaspace/" # Build font information caches fc-cache -f diff --git a/util/install_macos.sh b/util/install_macos.sh index 38ccc710..b45a58fc 100755 --- a/util/install_macos.sh +++ b/util/install_macos.sh @@ -4,11 +4,14 @@ set -euo pipefail origin=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) || exit +input_dir="${origin}/../fonts" +fonts_dir="${HOME}/Library/Fonts" + # remove all fonts from ~/Library/Fonts that start with "Monaspace" -rm -rf ~/Library/Fonts/Monaspace* +rm -rf "${fonts_dir}"/Monaspace* # copy all fonts from ./otf to ~/Library/Fonts -cp "${origin}/../fonts/otf/"* ~/Library/Fonts +cp "${input_dir}/otf/"* "${fonts_dir}" # copy variable fonts from ./variable to ~/Library/Fonts -cp "${origin}/../fonts/variable/"* ~/Library/Fonts \ No newline at end of file +cp "${input_dir}/variable/"* "${fonts_dir}" \ No newline at end of file