From 08a01e037c915257469755c67d38e3aabe407220 Mon Sep 17 00:00:00 2001 From: Ellie Huxtable Date: Sat, 21 Oct 2023 12:34:23 +0100 Subject: [PATCH] Add bash support to `enter_accept` (#1316) --- atuin-common/src/utils.rs | 7 ++++++- atuin/src/command/client/search/interactive.rs | 2 +- atuin/src/shell/atuin.bash | 14 +++++++++++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/atuin-common/src/utils.rs b/atuin-common/src/utils.rs index 65fa40c..8358802 100644 --- a/atuin-common/src/utils.rs +++ b/atuin-common/src/utils.rs @@ -119,10 +119,15 @@ pub fn is_zsh() -> bool { } pub fn is_fish() -> bool { - // only set on zsh + // only set on fish env::var("ATUIN_SHELL_FISH").is_ok() } +pub fn is_bash() -> bool { + // only set on bash + env::var("ATUIN_SHELL_BASH").is_ok() +} + #[cfg(test)] mod tests { use time::Month; diff --git a/atuin/src/command/client/search/interactive.rs b/atuin/src/command/client/search/interactive.rs index d900433..25fd6bc 100644 --- a/atuin/src/command/client/search/interactive.rs +++ b/atuin/src/command/client/search/interactive.rs @@ -703,7 +703,7 @@ pub async fn history( if index < results.len() { let mut command = results.swap_remove(index).command; - if accept && (utils::is_zsh() || utils::is_fish()) { + if accept && (utils::is_zsh() || utils::is_fish() || utils::is_bash()) { command = String::from("__atuin_accept__:") + &command; } diff --git a/atuin/src/shell/atuin.bash b/atuin/src/shell/atuin.bash index 7b862bf..2008d10 100644 --- a/atuin/src/shell/atuin.bash +++ b/atuin/src/shell/atuin.bash @@ -18,10 +18,18 @@ _atuin_precmd() { __atuin_history() { # shellcheck disable=SC2048,SC2086 - HISTORY="$(ATUIN_LOG=error atuin search $* -i -- "${READLINE_LINE}" 3>&1 1>&2 2>&3)" + HISTORY="$(ATUIN_SHELL_BASH=t ATUIN_LOG=error atuin search $* -i -- "${READLINE_LINE}" 3>&1 1>&2 2>&3)" + + if [[ $HISTORY == __atuin_accept__:* ]] + then + HISTORY=${HISTORY#__atuin_accept__:} + + eval "$HISTORY" + else + READLINE_LINE=${HISTORY} + READLINE_POINT=${#READLINE_LINE} + fi - READLINE_LINE=${HISTORY} - READLINE_POINT=${#READLINE_LINE} } if [[ -n "${BLE_VERSION-}" ]]; then