fix(bash): respect PROMPT_COMMAND as an array

This commit is contained in:
L. Yeung 2024-08-24 12:17:14 +08:00 committed by Jan De Dobbeleer
parent e2626c8668
commit 0644c93a67

View file

@ -36,7 +36,7 @@ function _omp_set_cursor_position() {
local COL
local ROW
IFS=';' read -sdR -p $'\E[6n' ROW COL
IFS=';' read -rsdR -p $'\E[6n' ROW COL
stty "$oldstty"
@ -92,10 +92,10 @@ function _omp_print_secondary() {
}
function _omp_hook() {
_omp_status_cache=$? _omp_pipestatus_cache=(${PIPESTATUS[@]})
_omp_status_cache=$? _omp_pipestatus_cache=("${PIPESTATUS[@]}")
if [[ ${#BP_PIPESTATUS[@]} -ge ${#_omp_pipestatus_cache[@]} ]]; then
_omp_pipestatus_cache=(${BP_PIPESTATUS[@]})
_omp_pipestatus_cache=("${BP_PIPESTATUS[@]}")
fi
_omp_stack_count=$((${#DIRSTACK[@]} - 1))
@ -120,6 +120,16 @@ function _omp_hook() {
return $_omp_status_cache
}
if [[ $TERM != linux ]] && ! [[ $PROMPT_COMMAND =~ _omp_hook ]]; then
PROMPT_COMMAND="_omp_hook; $PROMPT_COMMAND"
fi
function _omp_install_hook() {
[[ $TERM = linux ]] && return
local cmd
for cmd in "${PROMPT_COMMAND[@]}"; do
if [[ $cmd = "_omp_hook" ]]; then
return
fi
done
PROMPT_COMMAND=(_omp_hook "${PROMPT_COMMAND[@]}")
}
_omp_install_hook