pub fn hook(binary: &str) -> String {
format!(
r#"# >>> colorant init >>>
autoload -Uz add-zsh-hook
_colorant_apply() {{
"{bin}" apply >/dev/tty 2>/dev/null || true
}}
add-zsh-hook chpwd _colorant_apply
add-zsh-hook precmd _colorant_apply
_colorant_apply
# <<< colorant init <<<
"#,
bin = binary
)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn embeds_binary_path() {
let s = hook("/usr/local/bin/colorant");
assert!(s.contains("/usr/local/bin/colorant"));
assert!(s.contains("add-zsh-hook chpwd"));
assert!(s.contains("add-zsh-hook precmd"));
}
#[test]
fn has_begin_end_markers() {
let s = hook("colorant");
assert!(s.contains("# >>> colorant init >>>"));
assert!(s.contains("# <<< colorant init <<<"));
}
}