aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEllie Huxtable <ellie@elliehuxtable.com>2023-03-20 09:26:54 +0000
committerGitHub <noreply@github.com>2023-03-20 09:26:54 +0000
commitdcd77749dd1fdf6b0c8183bfbdf4f97bf238ebe4 (patch)
tree97c623911eeb52da65c2b3fd80092f2c86f3dd18 /src
parentskim-demo (#695) (diff)
downloadatuin-dcd77749dd1fdf6b0c8183bfbdf4f97bf238ebe4.zip
Add history deletion (#791)
* Drop events. I'd still like to do them, but differently * Start adding delete api stuff * Set mailmap * Delete delete delete * Fix tests * Make clippy happy
Diffstat (limited to '')
-rw-r--r--src/command/client/history.rs2
-rw-r--r--src/command/client/search.rs28
2 files changed, 21 insertions, 9 deletions
diff --git a/src/command/client/history.rs b/src/command/client/history.rs
index 8735123e..c8f6b535 100644
--- a/src/command/client/history.rs
+++ b/src/command/client/history.rs
@@ -184,7 +184,7 @@ impl Cmd {
// store whatever is ran, than to throw an error to the terminal
let cwd = utils::get_current_dir();
- let h = History::new(chrono::Utc::now(), command, cwd, -1, -1, None, None);
+ let h = History::new(chrono::Utc::now(), command, cwd, -1, -1, None, None, None);
// print the ID
// we use this as the key for calling end
diff --git a/src/command/client/search.rs b/src/command/client/search.rs
index 0a728cc5..dd6fcb32 100644
--- a/src/command/client/search.rs
+++ b/src/command/client/search.rs
@@ -76,6 +76,10 @@ pub struct Cmd {
#[arg(long)]
cmd_only: bool,
+ // Delete anything matching this query. Will not print out the match
+ #[arg(long)]
+ delete: bool,
+
/// Available variables: {command}, {directory}, {duration}, {user}, {host} and {time}.
/// Example: --format "{time} - [{duration}] - {directory}$\t{command}"
#[arg(long, short)]
@@ -100,12 +104,10 @@ impl Cmd {
let list_mode = ListMode::from_flags(self.human, self.cmd_only);
let entries = run_non_interactive(
settings,
- list_mode,
self.cwd,
self.exit,
self.exclude_exit,
self.exclude_cwd,
- self.format,
self.before,
self.after,
self.limit,
@@ -113,9 +115,22 @@ impl Cmd {
db,
)
.await?;
- if entries == 0 {
+
+ if entries.is_empty() {
std::process::exit(1)
}
+
+ // if we aren't deleting, print it all
+ if self.delete {
+ // delete it
+ // it only took me _years_ to add this
+ // sorry
+ for entry in entries {
+ db.delete(entry).await?;
+ }
+ } else {
+ super::history::print_list(&entries, list_mode, self.format.as_deref());
+ }
};
Ok(())
}
@@ -126,18 +141,16 @@ impl Cmd {
#[allow(clippy::too_many_arguments)]
async fn run_non_interactive(
settings: &Settings,
- list_mode: ListMode,
cwd: Option<String>,
exit: Option<i64>,
exclude_exit: Option<i64>,
exclude_cwd: Option<String>,
- format: Option<String>,
before: Option<String>,
after: Option<String>,
limit: Option<i64>,
query: &[String],
db: &mut impl Database,
-) -> Result<usize> {
+) -> Result<Vec<History>> {
let dir = if cwd.as_deref() == Some(".") {
Some(utils::get_current_dir())
} else {
@@ -202,6 +215,5 @@ async fn run_non_interactive(
.map(std::borrow::ToOwned::to_owned)
.collect();
- super::history::print_list(&results, list_mode, format.as_deref());
- Ok(results.len())
+ Ok(results)
}