summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEllie Huxtable <ellie@elliehuxtable.com>2024-03-12 17:04:02 +0000
committerGitHub <noreply@github.com>2024-03-12 17:04:02 +0000
commit6aa90c0eedc8f06afbb9046884b51e14bf6c3946 (patch)
treeef954e9738e43d05acfb77f7c75aa38db5c05b0f
parent02d79feea5d2c4abeae7a21f7d2ab749acb9e77d (diff)
fix: pass search query in via env (#1865)
* fix: pass search query in via env * fix
-rw-r--r--atuin/src/command/client/search.rs30
-rw-r--r--atuin/src/shell/atuin.bash4
-rw-r--r--atuin/src/shell/atuin.fish2
-rw-r--r--atuin/src/shell/atuin.xsh3
-rw-r--r--atuin/src/shell/atuin.zsh4
5 files changed, 26 insertions, 17 deletions
diff --git a/atuin/src/command/client/search.rs b/atuin/src/command/client/search.rs
index 27e26b25..f3626afe 100644
--- a/atuin/src/command/client/search.rs
+++ b/atuin/src/command/client/search.rs
@@ -2,7 +2,7 @@ use std::io::{stderr, IsTerminal as _};
use atuin_common::utils::{self, Escapable as _};
use clap::Parser;
-use eyre::{eyre, Result};
+use eyre::Result;
use atuin_client::{
database::Database,
@@ -121,22 +121,30 @@ pub struct Cmd {
}
impl Cmd {
+ // clippy: please write this instead
+ // clippy: now it has too many lines
+ // me: I'll do it later OKAY
+ #[allow(clippy::too_many_lines)]
pub async fn run(
self,
db: impl Database,
settings: &mut Settings,
store: SqliteStore,
) -> 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 {
- vec![]
- };
+ let query = self.query.map_or_else(
+ || {
+ std::env::var("ATUIN_QUERY").map_or_else(
+ |_| vec![],
+ |query| {
+ query
+ .split(' ')
+ .map(std::string::ToString::to_string)
+ .collect()
+ },
+ )
+ },
+ |query| query,
+ );
if (self.delete_it_all || self.delete) && self.limit.is_some() {
// Because of how deletion is implemented, it will always delete all matches
diff --git a/atuin/src/shell/atuin.bash b/atuin/src/shell/atuin.bash
index 3394da2e..38f58c59 100644
--- a/atuin/src/shell/atuin.bash
+++ b/atuin/src/shell/atuin.bash
@@ -227,7 +227,7 @@ __atuin_history() {
local READLINE_LINE="" READLINE_POINT=0
local __atuin_output
- __atuin_output=$(ATUIN_SHELL_BASH=t ATUIN_LOG=error atuin search "$@" -i -- "$READLINE_LINE" 3>&1 1>&2 2>&3)
+ __atuin_output=$(ATUIN_SHELL_BASH=t ATUIN_LOG=error ATUIN_QUERY="$READLINE_LINE" atuin search "$@" -i 3>&1 1>&2 2>&3)
# We do nothing when the search is canceled.
[[ $__atuin_output ]] || return 0
@@ -265,7 +265,7 @@ if [[ ${BLE_VERSION-} ]] && ((_ble_version >= 400)); then
#
function ble/complete/auto-complete/source:atuin-history {
local suggestion
- suggestion=$(atuin search --cmd-only --limit 1 --search-mode prefix -- "$_ble_edit_str")
+ suggestion=$(ATUIN_QUERY="$_ble_edit_str" atuin search --cmd-only --limit 1 --search-mode prefix)
[[ $suggestion == "$_ble_edit_str"?* ]] || return 1
ble/complete/auto-complete/enter h 0 "${suggestion:${#_ble_edit_str}}" '' "$suggestion"
}
diff --git a/atuin/src/shell/atuin.fish b/atuin/src/shell/atuin.fish
index b10d70ec..6ef1e2d2 100644
--- a/atuin/src/shell/atuin.fish
+++ b/atuin/src/shell/atuin.fish
@@ -35,7 +35,7 @@ function _atuin_search
# In fish 3.4 and above we can use `"$(some command)"` to keep multiple lines separate;
# but to support fish 3.3 we need to use `(some command | string collect)`.
# https://fishshell.com/docs/current/relnotes.html#id24 (fish 3.4 "Notable improvements and fixes")
- set -l ATUIN_H (ATUIN_SHELL_FISH=t ATUIN_LOG=error atuin search --keymap-mode=$keymap_mode $argv -i -- (commandline -b) 3>&1 1>&2 2>&3 | string collect)
+ set -l ATUIN_H (ATUIN_SHELL_FISH=t ATUIN_LOG=error ATUIN_QUERY=(commandline -b) atuin search --keymap-mode=$keymap_mode $argv -i 3>&1 1>&2 2>&3 | string collect)
if test -n "$ATUIN_H"
if string match --quiet '__atuin_accept__:*' "$ATUIN_H"
diff --git a/atuin/src/shell/atuin.xsh b/atuin/src/shell/atuin.xsh
index 486d7784..d504c627 100644
--- a/atuin/src/shell/atuin.xsh
+++ b/atuin/src/shell/atuin.xsh
@@ -32,10 +32,11 @@ def _atuin_postcommand(cmd: str, rtn: int, out, ts):
def _search(event, extra_args: list[str]):
buffer = event.current_buffer
- cmd = ["atuin", "search", "--interactive", *extra_args, "--", buffer.text]
+ cmd = ["atuin", "search", "--interactive", *extra_args]
# We need to explicitly pass in xonsh env, in case user has set XDG_HOME or something else that matters
env = ${...}.detype()
env["ATUIN_SHELL_XONSH"] = "t"
+ env["ATUIN_QUERY"] = buffer.text
p = subprocess.run(cmd, stderr=subprocess.PIPE, encoding="utf-8", env=env)
result = p.stderr.rstrip("\n")
diff --git a/atuin/src/shell/atuin.zsh b/atuin/src/shell/atuin.zsh
index 8cfba3b4..d580f704 100644
--- a/atuin/src/shell/atuin.zsh
+++ b/atuin/src/shell/atuin.zsh
@@ -15,7 +15,7 @@ zmodload zsh/datetime 2>/dev/null
# you'd like to override this, then add your config after the $(atuin init zsh)
# in your .zshrc
_zsh_autosuggest_strategy_atuin() {
- suggestion=$(atuin search --cmd-only --limit 1 --search-mode prefix -- "$1")
+ suggestion=$(ATUIN_QUERY="$1" atuin search --cmd-only --limit 1 --search-mode prefix)
}
if [ -n "${ZSH_AUTOSUGGEST_STRATEGY:-}" ]; then
@@ -56,7 +56,7 @@ _atuin_search() {
# TODO: not this
local output
# shellcheck disable=SC2048
- output=$(ATUIN_SHELL_ZSH=t ATUIN_LOG=error atuin search $* -i -- $BUFFER 3>&1 1>&2 2>&3)
+ output=$(ATUIN_SHELL_ZSH=t ATUIN_LOG=error ATUIN_QUERY=$BUFFER atuin search $* -i 3>&1 1>&2 2>&3)
zle reset-prompt