all repos — bibel @ 24fb7ab0d94eef6e9a9dab5d2553b861096d5889

Unnamed repository; edit this file 'description' to name the repository.

feat: add XDG data directory support for automatic Bible file discovery

- Add XDG data directory support (`internal/config.go`)
  - Automatically search `$XDG_DATA_HOME/bibel` for JSON files when
    `bible_path` is empty
  - Implement `findBibleFileInDataDir()` to locate first `.json` file
  - Print confirmation message when using Bible file from XDG data
    directory
  - Provide helpful error messages when directory missing or no JSON
    files found
- Change default configuration (`configs/config.example.toml`)
  - Set `bible_path` to empty string (uses XDG-standard data directory)
  - Update documentation comments to explain XDG behavior
- Improve error handling (`internal/dateprogression.go`)
  - Add check for zero total verses to prevent divide-by-zero panic
  - Return clear error when Bible file lacks books for selected reading
    mode
- Update `--generate-config` flag to create config with empty
  `bible_path` for XDG compatibility
- Revise `README.md` to document XDG data directory usage and update
  project structure
- Add `CHANGELOG.md` entry for version 1.5.0 with XDG support,
  configuration changes, and fixed edge cases
Maxwell Jensen 85795372+maxwelljens@users.noreply.github.com
Fri, 17 Apr 2026 17:31:50 +0200
commit

24fb7ab0d94eef6e9a9dab5d2553b861096d5889

parent

9410cd8d1fb198ef5a049c595cb51e4f5587e5e7

5 files changed, 75 insertions(+), 5 deletions(-)

jump to
M CHANGELOG.mdCHANGELOG.md

@@ -8,6 +8,36 @@ [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased] +## [1.5.0] - 2026-04-17 + +### Added + +- **XDG data directory support**: Automatic Bible file discovery in +`$XDG_DATA_HOME/bibel` + - When `bible_path` is empty in configuration, program searches + `$XDG_DATA_HOME/bibel` for JSON files + - Uses first `.json` file found in the directory. Provides helpful error + messages when directory or Bible files are missing. +- **Cross-platform Bible data management**: Leverages `xdg` library for +consistent data directory paths across platforms + +### Changed + +- **Default configuration**: `bible_path` now defaults to empty string (uses +XDG-stadnard data directory) +- **Example configuration**: Updated `config.example.toml` with documentation +about XDG data directory usage +- **Error handling**: Improved error messages for missing Bible data files + +### Fixed + +- **Configuration generation**: `--generate-config` flag creates config with +empty `bible_path` for XDG compatibility +- **Edge case handling**: Prevent crashes when Bible file doesn't contain books +for selected reading mode +- **Date progression robustness**: Added check for zero total verses to prevent +divide-by-zero panics + ## [1.4.0] - 2026-04-17 ### Added
M README.mdREADME.md

@@ -142,7 +142,7 @@ .

├── cmd/bibel.go # Main CLI entry point ├── configs/ # Default configuration files │ └── config.example.toml # The default configuration file -├── internal/ +├── internal/ │ ├── config.go # Reading and writing to config │ ├── dateprogression.go # Date-based position calculation │ ├── verse.go # Data structures
M configs/config.example.tomlconfigs/config.example.toml

@@ -5,8 +5,9 @@ # Output mode: "tui" (interactive terminal UI), "formatted" (ANSI-coloured text),

# or "plain" (plain text without formatting) output_mode = "tui" -# Path to Bible data file (relative to executable or absolute path) -bible_path = "books/pol_nbg.json" +# Path to Bible data file (relative to executable or absolute path). If empty, +# automatically uses first JSON file found in $XDG_DATA_HOME/bibel +bible_path = "" # Reading mode: "evangelion" (four Gospels), "new_testament", "old_testament", "bible" reading_mode = "evangelion"

@@ -39,4 +40,4 @@ verses_per_day = 12

# Start date for yearly progression (format: "1 January") # Empty means 1 January of current year - start_date = ""+ start_date = ""
M internal/config.gointernal/config.go

@@ -9,6 +9,32 @@ "github.com/adrg/xdg"

"github.com/spf13/viper" ) +// findBibleFileInDataDir looks for Bible JSON files in the XDG data directory +// It returns the path to the first JSON file found, or an error if none found +func findBibleFileInDataDir() (string, error) { + dataDir := filepath.Join(xdg.DataHome, "bibel") + + // Check if the directory exists + if _, err := os.Stat(dataDir); os.IsNotExist(err) { + return "", fmt.Errorf("Bible data directory not found: %s\nPlease create this directory and add Bible JSON files to it", dataDir) + } + + // Read the directory + entries, err := os.ReadDir(dataDir) + if err != nil { + return "", fmt.Errorf("error reading Bible data directory %s: %w", dataDir, err) + } + + // Look for JSON files + for _, entry := range entries { + if !entry.IsDir() && filepath.Ext(entry.Name()) == ".json" { + return filepath.Join(dataDir, entry.Name()), nil + } + } + + return "", fmt.Errorf("no JSON Bible files found in %s\nPlease add Bible JSON files to this directory", dataDir) +} + // Config represents the application configuration type Config struct { // Reading mode: "evangelion", "new_testament", "old_testament", "bible"

@@ -64,7 +90,7 @@ func DefaultConfig() *Config {

cfg := &Config{ ReadingMode: "evangelion", OutputMode: "tui", - BiblePath: "books/pol_nbg.json", + BiblePath: "", // Empty means use XDG data directory } cfg.TUI.ShowQuitMessage = true

@@ -146,6 +172,16 @@ cfg.TUI.BorderStyle = defaultCfg.TUI.BorderStyle

} if cfg.DateProgression.VersesPerDay == 0 { cfg.DateProgression.VersesPerDay = defaultCfg.DateProgression.VersesPerDay + } + + // If BiblePath is still empty (default or from config), try to find a Bible file in XDG data directory + if cfg.BiblePath == "" { + biblePath, err := findBibleFileInDataDir() + if err != nil { + return nil, fmt.Errorf("failed to find Bible data file: %w", err) + } + cfg.BiblePath = biblePath + fmt.Fprintf(os.Stderr, "Using Bible file from XDG data directory: %s\n", cfg.BiblePath) } // Validate configuration
M internal/dateprogression.gointernal/dateprogression.go

@@ -94,6 +94,9 @@

// If we've gone through all books and offset is still positive, wrap // around to beginning (start over) Calculate modulo offset within total verses totalVerses := dp.GetTotalVersesForMode() + if totalVerses == 0 { + return nil, fmt.Errorf("no verses found for reading mode %s. The Bible data file may not contain books for this reading mode", dp.readingMode) + } if offset >= 0 { adjustedOffset := offset % totalVerses // Recursively find position for adjusted offset