mirror of
https://github.com/atuinsh/atuin.git
synced 2025-06-20 18:07:57 +02:00
fix(bash): fix small issues of enter_accept
for the plain Bash (#1467)
* fix(bash): history should be updated before preexec * fix(bash): properly execute "--" With the current implementation, the user command "--" would not be executed even if it were the intended one. This is because it would be confused as an option by the "eval" builtin. We can specify "--" to tell "eval" that the later arguments should be literally treated as the command. * fix(bash): correctly restore $? and $_ * fix(bash): fix the use of preexec_ret_value The exit status of preexec_ret_value is used to suppress the execution of the corresponding command in the extdebug mode. The current implementation somehow tries to set $? before the call of stty, which does not have any effect. Instead, we can manually turn off the execution of the user command when the condition matches. * feat(bash): support array PROMPT_COMMAND of Bash >= 5.1
This commit is contained in:
parent
7fe152a8a7
commit
1350d3fd74
@ -41,6 +41,9 @@ __atuin_history() {
|
|||||||
fi
|
fi
|
||||||
echo "${PS1@P}$HISTORY"
|
echo "${PS1@P}$HISTORY"
|
||||||
|
|
||||||
|
# Add it to the bash history
|
||||||
|
history -s "$HISTORY"
|
||||||
|
|
||||||
# Assuming bash-preexec
|
# Assuming bash-preexec
|
||||||
# Invoke every function in the preexec array
|
# Invoke every function in the preexec array
|
||||||
local preexec_function
|
local preexec_function
|
||||||
@ -56,31 +59,36 @@ __atuin_history() {
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
# shellcheck disable=SC2154
|
|
||||||
__atuin_set_ret_value "$preexec_ret_value" "$__bp_last_argument_prev_command"
|
|
||||||
|
|
||||||
# Juggle the terminal settings so that the command can be interacted with
|
# If extdebug is turned on and any preexec function returns non-zero
|
||||||
local stty_backup
|
# exit status, we do not run the user command.
|
||||||
stty_backup=$(stty -g)
|
if ! { shopt -q extdebug && ((preexec_ret_value)); }; then
|
||||||
stty "$ATUIN_STTY"
|
# Juggle the terminal settings so that the command can be interacted with
|
||||||
|
local stty_backup
|
||||||
|
stty_backup=$(stty -g)
|
||||||
|
stty "$ATUIN_STTY"
|
||||||
|
|
||||||
eval "$HISTORY"
|
# Execute the command. Note: We need to record $? and $_ after the
|
||||||
exit_status=$?
|
# user command within the same call of "eval" because $_ is otherwise
|
||||||
|
# overwritten by the last argument of "eval".
|
||||||
|
__atuin_set_ret_value "${__bp_last_ret_value-}" "${__bp_last_argument_prev_command-}"
|
||||||
|
eval -- "$HISTORY"$'\n__bp_last_ret_value=$? __bp_last_argument_prev_command=$_'
|
||||||
|
|
||||||
stty "$stty_backup"
|
stty "$stty_backup"
|
||||||
|
fi
|
||||||
|
|
||||||
# Execute preprompt commands
|
# Execute preprompt commands
|
||||||
__atuin_set_ret_value "$exit_status" "$HISTORY"
|
local __atuin_prompt_command
|
||||||
eval "$PROMPT_COMMAND"
|
for __atuin_prompt_command in "${PROMPT_COMMAND[@]}"; do
|
||||||
# Add it to the bash history
|
__atuin_set_ret_value "${__bp_last_ret_value-}" "${__bp_last_argument_prev_command-}"
|
||||||
history -s "$HISTORY"
|
eval -- "$__atuin_prompt_command"
|
||||||
|
done
|
||||||
# Bash will redraw only the line with the prompt after we finish,
|
# Bash will redraw only the line with the prompt after we finish,
|
||||||
# so to work for a multiline prompt we need to print it ourselves,
|
# so to work for a multiline prompt we need to print it ourselves,
|
||||||
# then move up a line
|
# then move up a line
|
||||||
__atuin_set_ret_value "$exit_status" "$HISTORY"
|
__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_set_ret_value "$exit_status" "$HISTORY"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
READLINE_LINE=""
|
READLINE_LINE=""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user