githubnext / monaspace

An innovative superfamily of fonts for code
https://monaspace.githubnext.com
SIL Open Font License 1.1
13.15k stars 219 forks source link

Linux Bash script is wrong. FIX HERE! #93

Closed ghost closed 1 month ago

ghost commented 7 months ago

The util/install_linux.sh script is badly written and does not work properly. Here is the fixed script:

#!/bin/bash

# if the folder does not exist, create the folder
mkdir -p $HOME/.local/share/fonts/monaspace

# remove all fonts from ~/.local/share/fonts that start with "Monaspace"
rm -rf $HOME/.local/share/fonts/monaspace/Monaspace*

# copy all fonts from ./otf to ~/.local/share/fonts
cp $HOME/monaspace/fonts/otf/* $HOME/.local/share/fonts/monaspace

# copy variable fonts from ./variable to ~/.local/share/fonts
cp $HOME/monaspace/fonts/variable/* $HOME/.local/share/fonts/monaspace

# Build font information caches
fc-cache -f

Changes

  1. Now, if the folder fonts does not exist, create the folder inside $HOME/.local/share/
  2. The script now creates a folder called monaspace to keep the files there, keeping the fonts folder cleaner.
  3. Now to copy the files, the direction of the folder is specified to avoid the cp: cannot stat error
  4. Now use $HOME to make it easier for the user to read the script.

Particularities

We assume that the script is executed from the home folder of your system. Otherwise, the script will fail. The script expects the folder monaspace to be in your $HOME folder.

Observations

If you want, you can delete the follow command:

# remove all fonts from ~/.local/share/fonts that start with "Monaspace".
rm -rf $HOME/.local/share/fonts/monaspace/Monaspace*

And use cp -u instead. If you want to copy the file only if it is newer than the destination, invoke the command with the -u option, like this:

# copy all fonts from ./otf to ~/.local/share/fonts
cp -u $HOME/monaspace/fonts/otf/* $HOME/.local/share/fonts/monaspace

# copy variable fonts from ./variable to ~/.local/share/fonts
cp -u $HOME/monaspace/fonts/variable/* $HOME/.local/share/fonts/monaspace

And beyond

A script could be written to download and install automatically with a single .sh file.

#!/bin/bash

# download monaspace from github
git clone https://github.com/githubnext/monaspace.git

# create folders
mkdir -p $HOME/.local/share/fonts/monaspace

# remove all fonts from ~/.local/share/fonts that start with "Monaspace"
rm -rf $HOME/.local/share/fonts/monaspace/Monaspace*

# copy all fonts from ./otf to ~/.local/share/fonts
cp $HOME/monaspace/fonts/otf/* $HOME/.local/share/fonts/monaspace

# copy variable fonts from ./variable to ~/.local/share/fonts
cp $HOME/monaspace/fonts/variable/* $HOME/.local/share/fonts/monaspace

# Build font information caches
fc-cache -f

# after the install, delete the monaspace folder from your home folder
rm -rf ./monaspace

¡Un saludo!

TaylorMichaelHall commented 7 months ago

cp $HOME/monaspace/fonts/otf/* $HOME/.local/share/fonts/monaspace

This only works if you've cloned the repo to your home directory, though. We should just invoke the script from the root of the repo folder and not assume we know where it is located.

ghost commented 7 months ago

Okay, so in the following way, we avoid this problem. Again, we use mkdir -p and cp -u, we also indicate correctly with a double dot ../ which folder we want to copy. In short, this would be the solution.

Using cp -u you would not need to remove any previous fonts, this order allows copy the file only if it is newer than the destination.

#!/bin/bash

# if the folder does not exist, create the folder
mkdir -p $HOME/.local/share/fonts/monaspace

# copy all fonts from ../otf to ~/.local/share/fonts
cp -u ../fonts/otf/* $HOME/.local/share/fonts/monaspace

# copy variable fonts from ../variable to ~/.local/share/fonts
cp -u ../fonts/variable/* $HOME/.local/share/fonts/monaspace

# Build font information caches
fc-cache -f
tabrez commented 7 months ago

Alternatively, we can leave the cp commands to continue using the same paths as they do now and update the README.md file to use the correct path instead:

Current instructions for linux:

cd util
bash ./install_linux.sh

Update to:

bash util/install_linux.sh

Still need to add a command to add the destination directory if it doesn't exist as noted in the previous comments.

idan commented 1 month ago

Fixed in the batch of commits around 93c4bcdb772fe34c4aef415a87e1521ae9947012. Thank you!