feat(font): install system wide as root on Linux

This commit is contained in:
Jan De Dobbeleer 2024-06-10 16:08:11 +02:00 committed by Jan De Dobbeleer
parent 9122a8974b
commit 89beb8db68
2 changed files with 16 additions and 3 deletions

View file

@ -10,15 +10,23 @@ import (
"strings"
)
// FontsDir denotes the path to the user's fonts directory on Unix-like systems.
var FontsDir = path.Join(os.Getenv("HOME"), "/.local/share/fonts")
var (
fontsDir = path.Join(os.Getenv("HOME"), "/.local/share/fonts")
systemFontsDir = "/usr/share/fonts"
)
func install(font *Font, _ bool) error {
// If we're running as root, install the font system-wide.
targetDir := fontsDir
if os.Geteuid() == 0 {
targetDir = systemFontsDir
}
// On Linux, fontconfig can understand subdirectories. So, to keep the
// font directory clean, install all font files for a particular font
// family into a subdirectory named after the family (with hyphens instead
// of spaces).
fullPath := path.Join(FontsDir,
fullPath := path.Join(targetDir,
strings.ToLower(strings.ReplaceAll(font.Family, " ", "-")),
path.Base(font.FileName))

View file

@ -33,6 +33,11 @@ In case you have no admin rights, you can install the fonts by adding the `--use
Do know this can have side-effects when using certain applications.
:::
:::info Linux
On Linux, when running as root, the fonts will be installed system-wide.
When running as a regular user, the fonts will be installed in the user's font directory.
:::
```bash
oh-my-posh font install
```