mirror of
https://github.com/atuinsh/atuin.git
synced 2025-06-20 18:07:57 +02:00
fix: pass search query in via env (#1865)
* fix: pass search query in via env * fix
This commit is contained in:
parent
02d79feea5
commit
6aa90c0eed
@ -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::{eyre, Result};
|
use eyre::Result;
|
||||||
|
|
||||||
use atuin_client::{
|
use atuin_client::{
|
||||||
database::Database,
|
database::Database,
|
||||||
@ -121,22 +121,30 @@ pub struct Cmd {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl 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(
|
pub async fn run(
|
||||||
self,
|
self,
|
||||||
db: impl Database,
|
db: impl Database,
|
||||||
settings: &mut Settings,
|
settings: &mut Settings,
|
||||||
store: SqliteStore,
|
store: SqliteStore,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let query: Vec<String> = if let Some(query) = self.query {
|
let query = self.query.map_or_else(
|
||||||
query
|
|| {
|
||||||
} else if let Ok(query) = std::env::var("ATUIN_QUERY") {
|
std::env::var("ATUIN_QUERY").map_or_else(
|
||||||
|
|_| vec![],
|
||||||
|
|query| {
|
||||||
query
|
query
|
||||||
.split(' ')
|
.split(' ')
|
||||||
.map(std::string::ToString::to_string)
|
.map(std::string::ToString::to_string)
|
||||||
.collect()
|
.collect()
|
||||||
} else {
|
},
|
||||||
vec![]
|
)
|
||||||
};
|
},
|
||||||
|
|query| 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
|
||||||
|
@ -227,7 +227,7 @@ __atuin_history() {
|
|||||||
local READLINE_LINE="" READLINE_POINT=0
|
local READLINE_LINE="" READLINE_POINT=0
|
||||||
|
|
||||||
local __atuin_output
|
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.
|
# We do nothing when the search is canceled.
|
||||||
[[ $__atuin_output ]] || return 0
|
[[ $__atuin_output ]] || return 0
|
||||||
@ -265,7 +265,7 @@ if [[ ${BLE_VERSION-} ]] && ((_ble_version >= 400)); then
|
|||||||
#
|
#
|
||||||
function ble/complete/auto-complete/source:atuin-history {
|
function ble/complete/auto-complete/source:atuin-history {
|
||||||
local suggestion
|
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
|
[[ $suggestion == "$_ble_edit_str"?* ]] || return 1
|
||||||
ble/complete/auto-complete/enter h 0 "${suggestion:${#_ble_edit_str}}" '' "$suggestion"
|
ble/complete/auto-complete/enter h 0 "${suggestion:${#_ble_edit_str}}" '' "$suggestion"
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ function _atuin_search
|
|||||||
# In fish 3.4 and above we can use `"$(some command)"` to keep multiple lines separate;
|
# 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)`.
|
# 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")
|
# 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 test -n "$ATUIN_H"
|
||||||
if string match --quiet '__atuin_accept__:*' "$ATUIN_H"
|
if string match --quiet '__atuin_accept__:*' "$ATUIN_H"
|
||||||
|
@ -32,10 +32,11 @@ def _atuin_postcommand(cmd: str, rtn: int, out, ts):
|
|||||||
|
|
||||||
def _search(event, extra_args: list[str]):
|
def _search(event, extra_args: list[str]):
|
||||||
buffer = event.current_buffer
|
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
|
# We need to explicitly pass in xonsh env, in case user has set XDG_HOME or something else that matters
|
||||||
env = ${...}.detype()
|
env = ${...}.detype()
|
||||||
env["ATUIN_SHELL_XONSH"] = "t"
|
env["ATUIN_SHELL_XONSH"] = "t"
|
||||||
|
env["ATUIN_QUERY"] = buffer.text
|
||||||
|
|
||||||
p = subprocess.run(cmd, stderr=subprocess.PIPE, encoding="utf-8", env=env)
|
p = subprocess.run(cmd, stderr=subprocess.PIPE, encoding="utf-8", env=env)
|
||||||
result = p.stderr.rstrip("\n")
|
result = p.stderr.rstrip("\n")
|
||||||
|
@ -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)
|
# you'd like to override this, then add your config after the $(atuin init zsh)
|
||||||
# in your .zshrc
|
# in your .zshrc
|
||||||
_zsh_autosuggest_strategy_atuin() {
|
_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
|
if [ -n "${ZSH_AUTOSUGGEST_STRATEGY:-}" ]; then
|
||||||
@ -56,7 +56,7 @@ _atuin_search() {
|
|||||||
# TODO: not this
|
# TODO: not this
|
||||||
local output
|
local output
|
||||||
# shellcheck disable=SC2048
|
# 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
|
zle reset-prompt
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user