From 7813d1f493ce891c7f280cf0630255554f1ba389 Mon Sep 17 00:00:00 2001 From: Logan Donley Date: Sun, 8 Dec 2024 12:58:59 -0500 Subject: [PATCH] refining README and adding better error messages --- README.md | 39 +++++++++++++++++++++++++++++++++++--- internal/platform/linux.go | 19 +++++++++++++++++-- 2 files changed, 53 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 3aafaa8..4daced8 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,45 @@ # font-manager -A font installing utility for Linux and Mac. +A command-line utility for managing fonts on Linux and macOS. Designed for both manual and automated workflows. -## Quick Install +## Font sources +- Nerd fonts +- fontsource (includes google fonts) + +## Installation + +### Quick Install (Recommended) Install with the installation script: ```bash curl -sSL https://raw.githubusercontent.com/logandonley/font-manager/main/install.sh | bash ``` -Alternatively, download the relevant binary from the releases tab. +### Manual Installation + +1. Download the latest binary for your system from the releases page +2. (Optional, but recommended): Rename the file to fm: `mv fm` +3. Make the binary executable: `chmod +x ./fm` +4. Move it to your PATH: `sudo mv ./fm /usr/local/bin/` + +## Usage + +Basic command structure: + +```shell +fm [command] [options] +``` + +### Common use cases + +Download a single font + +```shell +fm install ComicShannsMono +``` + +Install multiple fonts + +```shell +fm install ComicShannsMono Inter Rubik +``` diff --git a/internal/platform/linux.go b/internal/platform/linux.go index 9f25adc..4778544 100644 --- a/internal/platform/linux.go +++ b/internal/platform/linux.go @@ -5,6 +5,7 @@ import ( "os" "os/exec" "path/filepath" + "strings" ) type linuxManager struct{} @@ -32,6 +33,11 @@ func (m *linuxManager) GetFontPaths() (FontPaths, error) { return paths, nil } +func hasSudo() bool { + _, err := exec.LookPath("sudo") + return err == nil +} + func (m *linuxManager) UpdateFontCache() error { // First try fc-cache if err := runCommand("fc-cache", "-f"); err == nil { @@ -40,8 +46,16 @@ func (m *linuxManager) UpdateFontCache() error { // If fc-cache fails, try with sudo (some distros require this) if os.Geteuid() != 0 { + if !hasSudo() { + return fmt.Errorf("font cache update failed. Please run 'fc-cache -f' manually with root privileges") + } + + fmt.Printf("Unable to update font cache with current permissions.\n") + fmt.Printf("This can happen if system-wide fonts were installed or if the cache is locked.\n") + fmt.Printf("Attempting to update with elevated privileges. You may be prompted for your password.\n\n") + if err := runCommand("sudo", "fc-cache", "-f"); err != nil { - return fmt.Errorf("updating font cache: %w", err) + return fmt.Errorf("updating font cache with elevated privileges: %w", err) } } @@ -51,7 +65,8 @@ func (m *linuxManager) UpdateFontCache() error { func runCommand(name string, args ...string) error { cmd := exec.Command(name, args...) if output, err := cmd.CombinedOutput(); err != nil { - return fmt.Errorf("running %s: %s: %w", name, output, err) + return fmt.Errorf("%s failed:\nCommand: %s %s\nOutput: %s\nError: %w", + name, name, strings.Join(args, " "), output, err) } return nil }