refactor(bash): factorize __atuin_accept_line (#1476)

This commit is contained in:
Koichi Murase 2024-01-02 00:20:16 +09:00 committed by GitHub
parent 1350d3fd74
commit c7db7838e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,18 +21,9 @@ __atuin_set_ret_value() {
return ${1:+"$1"} return ${1:+"$1"}
} }
__atuin_history() { __atuin_accept_line() {
# shellcheck disable=SC2048,SC2086 local HISTORY=$1
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__:}
if [[ -n "${BLE_ATTACHED-}" ]]; then
ble-edit/content/reset-and-check-dirty "$HISTORY"
ble/widget/accept-line
else
# Reprint the prompt, accounting for multiple lines # Reprint the prompt, accounting for multiple lines
local __atuin_prompt_offset local __atuin_prompt_offset
__atuin_prompt_offset=$(echo -n "${PS1@P}" | tr -cd '\n' | wc -c) __atuin_prompt_offset=$(echo -n "${PS1@P}" | tr -cd '\n' | wc -c)
@ -89,6 +80,21 @@ __atuin_history() {
__atuin_set_ret_value "${__bp_last_ret_value-}" "${__bp_last_argument_prev_command-}" __atuin_set_ret_value "${__bp_last_ret_value-}" "${__bp_last_argument_prev_command-}"
echo "${PS1@P}" echo "${PS1@P}"
tput cuu 1 tput cuu 1
}
__atuin_history() {
# shellcheck disable=SC2048,SC2086
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__:}
if [[ -n "${BLE_ATTACHED-}" ]]; then
ble-edit/content/reset-and-check-dirty "$HISTORY"
ble/widget/accept-line
else
__atuin_accept_line "$HISTORY"
fi fi
READLINE_LINE="" READLINE_LINE=""