diff --git a/bash-abbr b/bash-abbr index 183ca7b..1582a50 100644 --- a/bash-abbr +++ b/bash-abbr @@ -88,14 +88,18 @@ _try_abbrev_internal () { # Check if the character at point is a shell metacharacter or EOL [[ $point -eq ${#line} || "${line:point:1}" = [\<\>\&\;\(\)\|[:space:]] ]] && - # Determine word to complete. + # Determine word to complete # Uses the same word separators as bash (| & ; ( ) space tab newline) (aka "shell metacharacters") # But < and > are ignored, since they always expect a file/delimiter/string afterwards and not a command declare -r word_at_point=${line_until_point##*[&;()|[:space:]]} && - # Select replacement (if any). + # Select replacement (if any) declare replacement=${BASH_ALIASES["${word_at_point:-__nonexistent}"]-} && + # Account for file extension aliases. Normal aliases take precedence + declare file_extension_replacement=${BASH_ALIASES[".${word_at_point##*.}"]-} && + [[ $replacement ]] || { replacement=${file_extension_replacement:+${file_extension_replacement%!} $word_at_point${file_extension_replacement: -1}} && replacement=${replacement%[^!]}; } && + [[ $replacement ]] && # Determine if it's the first word of a simple command, unless we're expanding a global alias (prefix: "*" or "$"). @@ -123,7 +127,7 @@ _try_abbrev_internal () { # Recursively expand replacement if we haven't expanded it already declare tmp=" $replacement" - [[ $tmp =~ ^([[:space:]]*$is_first_word_prefix) ]] && tmp=${tmp#"${BASH_REMATCH[1]}"} || echo NO + [[ $tmp =~ ^([[:space:]]*$is_first_word_prefix) ]] && tmp=${tmp#"${BASH_REMATCH[1]}"} declare -r word_to_expand=${tmp%%[<>&;()|[:space:]]*} if [[ ! ${_expanded_aliases[$word_to_expand]-} ]]; then declare -r point_for_replacement=$((${#BASH_REMATCH[1]}+${#word_to_expand}))