From 17e66a1126e1aef460df2860b023172b3847e275 Mon Sep 17 00:00:00 2001 From: tsi Date: Sun, 26 Oct 2025 18:43:01 +0100 Subject: [PATCH] Add support for pre/post alias evaluation --- bash-abbr | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bash-abbr b/bash-abbr index 1582a50..e2647c0 100644 --- a/bash-abbr +++ b/bash-abbr @@ -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}