Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
19 changes: 11 additions & 8 deletions src/cmds/hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/cmds/hook/inactive.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion src/cmds/hook/stale.sh
Original file line number Diff line number Diff line change
@@ -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
20 changes: 18 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,33 @@ impl AsRef<Path> 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<T: Into<PathBuf>>(dir: Option<T>) -> Result<Config> {
let dir = match dir {
Expand Down