diff options
author | Ellie Huxtable <ellie@elliehuxtable.com> | 2023-10-21 12:34:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-21 12:34:23 +0100 |
commit | 08a01e037c915257469755c67d38e3aabe407220 (patch) | |
tree | 391361855c2b9923e674570fd8ede925ed2e69e8 | |
parent | d202afeaf5e81532217b6e6227990cf52b507604 (diff) |
Add bash support to `enter_accept` (#1316)
-rw-r--r-- | atuin-common/src/utils.rs | 7 | ||||
-rw-r--r-- | atuin/src/command/client/search/interactive.rs | 2 | ||||
-rw-r--r-- | 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 65fa40cf..8358802a 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 d900433e..25fd6bc0 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 7b862bf7..2008d107 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 |