Add support for pre/post alias evaluation

This commit is contained in:
tsi 2025-10-26 18:43:01 +01:00
parent 2d6f7ff2ab
commit 17e66a1126
No known key found for this signature in database

View file

@ -125,6 +125,10 @@ _try_abbrev_internal () {
# Strip special flags (or space) from the beginning of the replacement
replacement=${replacement#[*$ -]}
[[ ${replacement: -1} = "!" ]] && declare -r eval_expansion=true || declare -r eval_expansion=false
[[ ${replacement: -1} = "$" ]] && replacement=$(eval "${replacement%$}")
# Recursively expand replacement if we haven't expanded it already
declare tmp=" $replacement"
[[ $tmp =~ ^([[:space:]]*$is_first_word_prefix) ]] && tmp=${tmp#"${BASH_REMATCH[1]}"}
@ -136,6 +140,8 @@ _try_abbrev_internal () {
_try_abbrev_internal " $replacement" "$point_for_replacement" "" "ret_$level" "_" "_" ""
replacement=${recursively_expanded_replacement# }
fi
# Eval if it has a trailing exclamation point and strip trailing \n and \r
[[ $eval_expansion = true ]] && replacement=$(eval "${replacement%!}")
# Calculate point and mark offset.
declare -ir offset=${#replacement}-${#word_at_point}+${#self_insertion}