summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKjetil Jørgensen <kjetijor+github@gmail.com>2023-05-01 19:55:54 -0700
committerGitHub <noreply@github.com>2023-05-02 02:55:54 +0000
commit244a501cbbdc66a5c5fa3de220ca9257198fc4aa (patch)
tree6692b2a84699b797b1ef26be136881e0a6fbea43
parente222b598122759c6a7f4e2bbf5107470f8ad9ad7 (diff)
cwd_filter: much like history_filter, only it applies to cwd (#904)
* cwd_filter: much like history_filter, only it applies to cwd * appease clippy
-rw-r--r--atuin-client/config.toml9
-rw-r--r--atuin-client/src/settings.rs2
-rw-r--r--atuin/src/command/client/history.rs3
3 files changed, 14 insertions, 0 deletions
diff --git a/atuin-client/config.toml b/atuin-client/config.toml
index 1208586e..d8d0ddb2 100644
--- a/atuin-client/config.toml
+++ b/atuin-client/config.toml
@@ -73,3 +73,12 @@
# "^secret-cmd",
# "^innocuous-cmd .*--secret=.+"
# ]
+
+## prevent commands run with cwd matching any of these regexes from being written
+## to history. Note that these regular expressions are unanchored, i.e. if they don't
+## start with ^ or end with $, they'll match anyware in CWD.
+## For details on the supported regular expression syntax, see
+## https://docs.rs/regex/latest/regex/#syntax
+# cwd_filter = [
+# "^/very/secret/area"
+# ]
diff --git a/atuin-client/src/settings.rs b/atuin-client/src/settings.rs
index 0a723fb2..7da83913 100644
--- a/atuin-client/src/settings.rs
+++ b/atuin-client/src/settings.rs
@@ -154,6 +154,8 @@ pub struct Settings {
pub scroll_context_lines: usize,
#[serde(with = "serde_regex", default = "RegexSet::empty")]
pub history_filter: RegexSet,
+ #[serde(with = "serde_regex", default = "RegexSet::empty")]
+ pub cwd_filter: RegexSet,
// This is automatically loaded when settings is created. Do not set in
// config! Keep secrets and settings apart.
diff --git a/atuin/src/command/client/history.rs b/atuin/src/command/client/history.rs
index 4670e8c3..ea680014 100644
--- a/atuin/src/command/client/history.rs
+++ b/atuin/src/command/client/history.rs
@@ -198,6 +198,9 @@ impl Cmd {
// It's better for atuin to silently fail here and attempt to
// store whatever is ran, than to throw an error to the terminal
let cwd = utils::get_current_dir();
+ if !cwd.is_empty() && settings.cwd_filter.is_match(&cwd) {
+ return Ok(());
+ }
let h = History::new(chrono::Utc::now(), command, cwd, -1, -1, None, None, None);