Add support for file extension aliases
This commit is contained in:
parent
03302fd770
commit
2d6f7ff2ab
1 changed files with 7 additions and 3 deletions
10
bash-abbr
10
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}))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue