diff --git a/src/font/install_unix.go b/src/font/install_unix.go index 8ca43666e62b..a86e7e7eb54e 100644 --- a/src/font/install_unix.go +++ b/src/font/install_unix.go @@ -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)) diff --git a/website/docs/installation/fonts.mdx b/website/docs/installation/fonts.mdx index 92c57f097287..26b34c30541b 100644 --- a/website/docs/installation/fonts.mdx +++ b/website/docs/installation/fonts.mdx @@ -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 ```