Avoid accidentally deleting all history, but allow it if intended (#878)

* Avoid accidentally deleting all history, but allow it if intended

* docs
This commit is contained in:
Ellie Huxtable 2023-04-15 10:24:59 +01:00 committed by GitHub
parent 64671a17c1
commit d5515f5bcd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View file

@ -83,6 +83,10 @@ pub struct Cmd {
#[arg(long)]
delete: bool,
/// Delete EVERYTHING!
#[arg(long)]
delete_it_all: bool,
/// Reverse the order of results, oldest first
#[arg(long, short)]
reverse: bool,
@ -96,6 +100,18 @@ pub struct Cmd {
impl Cmd {
pub async fn run(self, mut db: impl Database, settings: &mut Settings) -> Result<()> {
if self.delete && self.query.is_empty() {
println!("Please specify a query to match the items you wish to delete. If you wish to delete all history, pass --delete-it-all");
return Ok(());
}
if self.delete_it_all && !self.query.is_empty() {
println!(
"--delete-it-all will delete ALL of your history! It does not require a query."
);
return Ok(());
}
if self.search_mode.is_some() {
settings.search_mode = self.search_mode.unwrap();
}
@ -131,7 +147,7 @@ impl Cmd {
}
// if we aren't deleting, print it all
if self.delete {
if self.delete || self.delete_it_all {
// delete it
// it only took me _years_ to add this
// sorry

View file

@ -22,6 +22,7 @@ appended with a wildcard).
| `--limit` | Limit the number of results (default: none) |
| `--offset` | Offset from the start of the results (default: none) |
| `--delete` | Delete history matching this query |
| `--delete-it-all` | Delete all shell history |
| `--reverse` | Reverse order of search results, oldest first |
## `atuin search -i`