xdg
xdg
Crystal implementation of the XDG Base Directory Specification with cross-platform support (Linux, macOS, Windows)
Provides standardized access to application configuration, data, and cache directories while respecting platform conventions and environment variables.
Installation
- Add the dependency to your
shard.yml
:
dependencies:
xdg:
github: dsisnero/xdg
- Run
shards install
Usage
# Creates parent directories with 0700 permissions if missing
config_file = XDG.app_config_path("myapp.cfg", create: true)
# Writes file with automatic directory creation (0700 for new dirs)
File.write(config_file, config_data) rescue puts "Save failed"
# Runtime directory security (must be 0700)
runtime_dir = XDG.runtime_dir! # Raises if permissions wrong
Key features:
- Automatic directory creation with 0700 permissions
- Existing directories remain untouched
- Strict security checks only for runtime directory
- Clean error hierarchy (XDG::Error > DirectoryError/SecurityError)
Development
- Clone the repo:
git clone https://github.com/dsisnero/xdg.git
- Install dependencies:
shards install
- Run tests:
crystal spec
Key components:
src/xdg.cr
: Core implementationspec/xdg_spec.cr
: Comprehensive test suite- Platform-specific logic handled through compile-time flags
Contributing
- Fork it (https://github.com/dsisnero/xdg/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Please include:
- Spec tests for new features
- Updates to documentation when applicable
- Cross-platform verification
Contributors
- Dominic Sisneros - creator and maintainer
Repository
xdg
Owner
Statistic
- 0
- 0
- 0
- 1
- 0
- 6 days ago
- March 6, 2025
License
MIT License
Links
Synced at
Wed, 07 May 2025 08:11:02 GMT
Languages