diff --git a/README.md b/README.md index bc8bac8..b64c32a 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,18 @@ eval "$(firstaide hook)" Then run `firstaide build` (or `firstaide --help`). +### Messages + +the `messages` section of `.firstaide.toml` allows you to configure the help text shown by direnv when the environment is inactive, stale, and loaded + +by default the messages are set as follows: + +```toml +[messages] +getting_started = "firstaide --help" # displayed when direnv loads successfully +stale = "firstaide build" +inactive = "build firstaide and run \"firstaide build\"" +``` ## To develop: diff --git a/src/cmds/hook.rs b/src/cmds/hook.rs index 9a2977d..dc8f95a 100644 --- a/src/cmds/hook.rs +++ b/src/cmds/hook.rs @@ -91,18 +91,18 @@ impl Command { ); env_diff.simplify(); if sums::equal(&sums_now, &cache.sums) { - let chunk_message = bash::escape(&config.messages.getting_started); - let chunk_content = - include_bytes!("hook/active.sh").replace(b"__MESSAGE__", chunk_message); + let getting_started_message = bash::escape(&config.messages.getting_started); + let chunk_content = include_bytes!("hook/active.sh") + .replace(b"__MESSAGE__", getting_started_message); handle .write_all(&chunk(&EnvironmentStatus::Okay.display(), &chunk_content)) .context("could not write active hook")?; } else { + let stale_message = bash::escape(&config.messages.stale); + let chunk_content = + include_bytes!("hook/stale.sh").replace(b"__MESSAGE__", stale_message); handle - .write_all(&chunk( - &EnvironmentStatus::Stale.display(), - include_bytes!("hook/stale.sh"), - )) + .write_all(&chunk(&EnvironmentStatus::Stale.display(), &chunk_content)) .context("could not write stale hook")?; } handle @@ -137,10 +137,13 @@ impl Command { } } Err(_) => { + let inactive_message = bash::escape(&config.messages.inactive); + let chunk_content = + include_bytes!("hook/inactive.sh").replace(b"__MESSAGE__", inactive_message); handle .write_all(&chunk( &EnvironmentStatus::Unknown.display(), - include_bytes!("hook/inactive.sh"), + &chunk_content, )) .context("could not write inactive hook")?; handle diff --git a/src/cmds/hook/inactive.sh b/src/cmds/hook/inactive.sh index ac97ead..a8038b8 100644 --- a/src/cmds/hook/inactive.sh +++ b/src/cmds/hook/inactive.sh @@ -1,3 +1,4 @@ # shellcheck shell=bash log_status "$(error ERROR): $(em 'Nix environment is not yet built!')" >&2 -log_status "--> Use $(em ./bootstrap) to build it." >&2 +log_status "--> Use $(em __MESSAGE__) to build it." >&2 +log_status " $(m=__MESSAGE__ && em "${m//?/^}")" >&2 diff --git a/src/cmds/hook/stale.sh b/src/cmds/hook/stale.sh index b88db26..520aaac 100644 --- a/src/cmds/hook/stale.sh +++ b/src/cmds/hook/stale.sh @@ -1,4 +1,5 @@ # shellcheck shell=bash log_status "$(warning WARNING): $(em 'Nix environment is out of date!') " >&2 -log_status "--> Use $(em firstaide-update) to rebuild it." >&2 +log_status "--> Use $(em __MESSAGE__) to rebuild it." >&2 +log_status " $(m=__MESSAGE__ && em "${m//?/^}")" >&2 log_status "$(warning WARNING): Loading $(em STALE) environment ;-(" >&2 diff --git a/src/config.rs b/src/config.rs index 23089cc..dc2e5f5 100644 --- a/src/config.rs +++ b/src/config.rs @@ -51,17 +51,33 @@ impl AsRef for ParentDir { #[derive(Debug, Deserialize)] pub struct Messages { + #[serde(default = "default_getting_started")] pub getting_started: String, + #[serde(default = "default_stale")] + pub stale: String, + #[serde(default = "default_inactive")] + pub inactive: String, } - impl Default for Messages { fn default() -> Self { Self { - getting_started: "aide --help".into(), + getting_started: default_getting_started(), + stale: default_stale(), + inactive: default_inactive(), } } } +fn default_getting_started() -> String { + "firstaide --help".to_string() +} +fn default_stale() -> String { + "firstaide build".to_string() +} +fn default_inactive() -> String { + "build firstaide and run \"firstaide build\"".to_string() +} + impl Config { pub fn load>(dir: Option) -> Result { let dir = match dir {