mirror of
https://github.com/atuinsh/atuin.git
synced 2025-02-19 20:01:08 +01:00
fix(bash): fix error by the use of ${PS1@P} in bash < 4.4 (#1488)
The parameter expansions for the prompt strings, `${PS1@P}`, is only available in bash >= 4.4. In Bash 4.3 or below w/ bash-preexec, the current implementation produces error messages. There is no way to evaluate PS1 with bash < 4.4, so we give up the adjustments for multiline prompts in bash < 4.4 in this patch.
This commit is contained in:
parent
f44db9d7f9
commit
16309ca198
@ -30,10 +30,18 @@ __atuin_set_ret_value() {
|
|||||||
return ${1:+"$1"}
|
return ${1:+"$1"}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# The expansion ${PS1@P} is available in bash >= 4.4.
|
||||||
|
if ((BASH_VERSINFO[0] >= 5 || BASH_VERSINFO[0] == 4 && BASH_VERSINFO[1] >= 4)); then
|
||||||
|
__atuin_use_prompt_expansion=true
|
||||||
|
else
|
||||||
|
__atuin_use_prompt_expansion=false
|
||||||
|
fi
|
||||||
|
|
||||||
__atuin_accept_line() {
|
__atuin_accept_line() {
|
||||||
local __atuin_command=$1
|
local __atuin_command=$1
|
||||||
|
|
||||||
# Reprint the prompt, accounting for multiple lines
|
# Reprint the prompt, accounting for multiple lines
|
||||||
|
if [[ $__atuin_use_prompt_expansion == true ]]; then
|
||||||
local __atuin_prompt=${PS1@P}
|
local __atuin_prompt=${PS1@P}
|
||||||
local __atuin_prompt_offset
|
local __atuin_prompt_offset
|
||||||
__atuin_prompt_offset=$(printf '%s' "$__atuin_prompt" | wc -l)
|
__atuin_prompt_offset=$(printf '%s' "$__atuin_prompt" | wc -l)
|
||||||
@ -41,6 +49,9 @@ __atuin_accept_line() {
|
|||||||
tput cuu "$__atuin_prompt_offset"
|
tput cuu "$__atuin_prompt_offset"
|
||||||
fi
|
fi
|
||||||
printf '%s\n' "$__atuin_prompt$__atuin_command"
|
printf '%s\n' "$__atuin_prompt$__atuin_command"
|
||||||
|
else
|
||||||
|
printf '%s\n' "\$ $__atuin_command"
|
||||||
|
fi
|
||||||
|
|
||||||
# Add it to the bash history
|
# Add it to the bash history
|
||||||
history -s "$__atuin_command"
|
history -s "$__atuin_command"
|
||||||
@ -87,8 +98,10 @@ __atuin_accept_line() {
|
|||||||
# 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 go to the beginning of the last line.
|
# then go to the beginning of the last line.
|
||||||
|
if [[ $__atuin_use_prompt_expansion == true ]]; then
|
||||||
__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-}"
|
||||||
printf '%s\r' "${PS1@P}"
|
printf '%s\r' "${PS1@P}"
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
__atuin_history() {
|
__atuin_history() {
|
||||||
|
Loading…
Reference in New Issue
Block a user