diff options
| author | duckyriley <[email protected]> | 2026-11-23 20:50:50 +0800 |
|---|---|---|
| committer | duckyriley <[email protected]> | 2026-11-23 20:50:50 +0800 |
| commit | 6bb21305adcf8155a8488bc69ebddd4edc710930 (patch) | |
| tree | a607bd6c2d63d3c4c51e8a395cc8ec0e1cf43d28 /src/config.rs | |
| parent | 24d7f554d00901841810b856b44d5763cbc5bd76 (diff) | |
| download | ducky-6bb21305adcf8155a8488bc69ebddd4edc710930.tar.gz ducky-6bb21305adcf8155a8488bc69ebddd4edc710930.zip | |
Support macOS app bundles and document Linux distro builds
Diffstat (limited to 'src/config.rs')
| -rw-r--r-- | src/config.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/config.rs b/src/config.rs index 65720e3..c1b00ae 100644 --- a/src/config.rs +++ b/src/config.rs @@ -29,7 +29,10 @@ pub struct Config { pub startup: Option<String>, } pub fn directory() -> PathBuf { - dirs::config_dir() + std::env::var_os("XDG_CONFIG_HOME") + .filter(|value| !value.is_empty()) + .map(PathBuf::from) + .or_else(dirs::config_dir) .unwrap_or_else(|| PathBuf::from(".")) .join("ducky") } @@ -57,6 +60,14 @@ impl Config { } pub(crate) fn parse(source: &str, dir: &std::path::Path) -> Result<Self> { let lua = Lua::new(); + let api = lua + .create_table() + .map_err(|e| anyhow::anyhow!(e.to_string()))?; + api.set("config_dir", dir.to_string_lossy().as_ref()) + .map_err(|e| anyhow::anyhow!(e.to_string()))?; + lua.globals() + .set("ducky", api) + .map_err(|e| anyhow::anyhow!(e.to_string()))?; let package: Table = lua .globals() .get("package") @@ -173,6 +184,12 @@ mod tests { assert_eq!(c.palette.len(), 16); } #[test] + fn prompt_path_uses_platform_config_directory() { + let dir = std::path::Path::new("/Users/example/Library/Application Support/ducky"); + let c = Config::parse(DEFAULT, dir).unwrap(); + assert_eq!(c.args[1], dir.join("shell.bash").to_string_lossy()); + } + #[test] fn rejects_bad_config() { assert!(Config::parse("return {font_size=0}", std::path::Path::new("/tmp")).is_err()); assert!(color("#ff").is_err()); |