From 8539e0308d8052aa82c5989158eb639cfddfc5a1 Mon Sep 17 00:00:00 2001 From: Johannes Kresner Date: Sun, 15 Nov 2026 22:05:56 +0100 Subject: [PATCH] feat: add local profiles inspection before global --- src/profile.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/profile.rs b/src/profile.rs index 9087637..0acb1e7 100644 --- a/src/profile.rs +++ b/src/profile.rs @@ -1,9 +1,19 @@ -//! Profile: `/profiles/NAME.toml`. One profile = one identity (own HOME/auth), budget and gate. +//! Profile: `./.hx/profiles/NAME.toml` (repo-local, checked first), else `/profiles/NAME.toml`. One profile = one identity (own HOME/auth), budget and gate. use anyhow::{Context, Result, bail}; use serde::Deserialize; use std::path::PathBuf; +/// `./.hx/profiles/NAME.toml` when it exists (repo-local wins), else `/profiles/NAME.toml`. +fn profile_path(name: &str) -> PathBuf { + let file = format!("{name}.toml"); + let local = PathBuf::from(".hx/profiles").join(&file); + if local.is_file() { + return local; + } + crate::config_dir().join("profiles").join(file) +} + /// [`Profile::add_allow`] on a file. fn add_allow_at(path: &std::path::Path, entry: &str) -> Result { crate::policy::check_entry(entry)?; @@ -172,9 +182,7 @@ impl Profile { if name.is_empty() || name.contains(['/', '.']) { bail!("bad profile name {name:?}"); } - let path = crate::config_dir() - .join("profiles") - .join(format!("{name}.toml")); + let path = profile_path(name); let s = match std::fs::read_to_string(&path) { // only the implicit profile may be missing; a typo in any other name must still fail Err(e) if name == "default" && e.kind() == std::io::ErrorKind::NotFound => { @@ -192,10 +200,7 @@ impl Profile { if name.is_empty() || name.contains(['/', '.']) { bail!("bad profile name {name:?}"); } - let path = crate::config_dir() - .join("profiles") - .join(format!("{name}.toml")); - add_allow_at(&path, entry) + add_allow_at(&profile_path(name), entry) } pub fn account<'a>(&'a self, profile: &'a str) -> &'a str {