Skip to content

Commit

Permalink
feat(font): install system wide as root on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
JanDeDobbeleer committed Jun 10, 2024
1 parent 9122a89 commit 89beb8d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/font/install_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
5 changes: 5 additions & 0 deletions website/docs/installation/fonts.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
Expand Down

0 comments on commit 89beb8d

Please sign in to comment.