mirror of
https://github.com/atuinsh/atuin.git
synced 2025-01-07 15:00:34 +01:00
feat(search): allow specifying search query as an env var (#1863)
This commit is contained in:
parent
04f2c95617
commit
3368d2fa47
@ -2,7 +2,7 @@ use std::io::{stderr, IsTerminal as _};
|
|||||||
|
|
||||||
use atuin_common::utils::{self, Escapable as _};
|
use atuin_common::utils::{self, Escapable as _};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use eyre::Result;
|
use eyre::{eyre, Result};
|
||||||
|
|
||||||
use atuin_client::{
|
use atuin_client::{
|
||||||
database::Database,
|
database::Database,
|
||||||
@ -83,7 +83,7 @@ pub struct Cmd {
|
|||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
human: bool,
|
human: bool,
|
||||||
|
|
||||||
query: Vec<String>,
|
query: Option<Vec<String>>,
|
||||||
|
|
||||||
/// Show only the text of the command
|
/// Show only the text of the command
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
@ -127,6 +127,17 @@ impl Cmd {
|
|||||||
settings: &mut Settings,
|
settings: &mut Settings,
|
||||||
store: SqliteStore,
|
store: SqliteStore,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
|
let query: Vec<String> = if let Some(query) = self.query {
|
||||||
|
query
|
||||||
|
} else if let Ok(query) = std::env::var("ATUIN_QUERY") {
|
||||||
|
query
|
||||||
|
.split(' ')
|
||||||
|
.map(std::string::ToString::to_string)
|
||||||
|
.collect()
|
||||||
|
} else {
|
||||||
|
return Err(eyre!("please specify search query via args or ATUIN_QUERY"));
|
||||||
|
};
|
||||||
|
|
||||||
if (self.delete_it_all || self.delete) && self.limit.is_some() {
|
if (self.delete_it_all || self.delete) && self.limit.is_some() {
|
||||||
// Because of how deletion is implemented, it will always delete all matches
|
// Because of how deletion is implemented, it will always delete all matches
|
||||||
// and disregard the limit option. It is also not clear what deletion with a
|
// and disregard the limit option. It is also not clear what deletion with a
|
||||||
@ -139,12 +150,12 @@ impl Cmd {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.delete && self.query.is_empty() {
|
if self.delete && 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");
|
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(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.delete_it_all && !self.query.is_empty() {
|
if self.delete_it_all && !query.is_empty() {
|
||||||
println!(
|
println!(
|
||||||
"--delete-it-all will delete ALL of your history! It does not require a query."
|
"--delete-it-all will delete ALL of your history! It does not require a query."
|
||||||
);
|
);
|
||||||
@ -177,7 +188,7 @@ impl Cmd {
|
|||||||
let history_store = HistoryStore::new(store.clone(), host_id, encryption_key);
|
let history_store = HistoryStore::new(store.clone(), host_id, encryption_key);
|
||||||
|
|
||||||
if self.interactive {
|
if self.interactive {
|
||||||
let item = interactive::history(&self.query, settings, db, &history_store).await?;
|
let item = interactive::history(&query, settings, db, &history_store).await?;
|
||||||
if stderr().is_terminal() {
|
if stderr().is_terminal() {
|
||||||
eprintln!("{}", item.escape_control());
|
eprintln!("{}", item.escape_control());
|
||||||
} else {
|
} else {
|
||||||
@ -197,7 +208,7 @@ impl Cmd {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mut entries =
|
let mut entries =
|
||||||
run_non_interactive(settings, opt_filter.clone(), &self.query, &db).await?;
|
run_non_interactive(settings, opt_filter.clone(), &query, &db).await?;
|
||||||
|
|
||||||
if entries.is_empty() {
|
if entries.is_empty() {
|
||||||
std::process::exit(1)
|
std::process::exit(1)
|
||||||
@ -221,7 +232,7 @@ impl Cmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
entries =
|
entries =
|
||||||
run_non_interactive(settings, opt_filter.clone(), &self.query, &db).await?;
|
run_non_interactive(settings, opt_filter.clone(), &query, &db).await?;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let format = match self.format {
|
let format = match self.format {
|
||||||
|
Loading…
Reference in New Issue
Block a user