Add bash support to enter_accept (#1316)

This commit is contained in:
Ellie Huxtable 2023-10-21 12:34:23 +01:00 committed by GitHub
parent d202afeaf5
commit 08a01e037c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 5 deletions

View file

@ -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;

View file

@ -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;
}

View file

@ -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