Skip to content

Commit

Permalink
refining README and adding better error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
logandonley committed Dec 8, 2024
1 parent 62965b4 commit 7813d1f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 5 deletions.
39 changes: 36 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 <Downloaded file> 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
```
19 changes: 17 additions & 2 deletions internal/platform/linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"
)

type linuxManager struct{}
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
}

Expand All @@ -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
}

0 comments on commit 7813d1f

Please # to comment.