aboutsummaryrefslogtreecommitdiffstats
path: root/src/config.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/config.rs19
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());