#1: Allow history expansion on metacharacter insertion (currently disabled because it moves the point)
This commit is contained in:
parent
bc3f414ab8
commit
91600446c6
1 changed files with 14 additions and 11 deletions
25
bash-abbr
25
bash-abbr
|
|
@ -4,12 +4,13 @@
|
|||
# put into the bashrc drop-in directory ~/.bashrc.d/
|
||||
# and then sourced from ~/.bashrc.
|
||||
|
||||
# WARNING: This plug-in creates a new readline binding: '\e\C-a'
|
||||
# and overwrites the binding for '\C-m', ' ', '|', '&', ';', '(', ')', '<', '>'
|
||||
# WARNING: This plug-in overwrites the readling bindings for ' ', '|', '&', ';', '(', ')', '<', '>'
|
||||
# It also creates new bindings '\e\C-a<x>' where `<x>` is one of the characters above.
|
||||
# Additionally, it overwrites the binding for '\C-m' and creates a corresponding binding '\e\C-an'.
|
||||
# Therefore, it might interfere with other plug-ins or custom bindings.
|
||||
# You may change the '\e\C-a' binding to whatever you want as it's only used
|
||||
# as a hook inside another readline macro. The bindings '|', '&', ';', '(', ')', '<', '>'
|
||||
# may also be dropped if you don't need them.
|
||||
# You may change the '\e\C-a' binding-"prefix" to whatever you want as it's only used
|
||||
# as a hook inside other readline macros. The bindings '|', '&', ';', '(', ')', '<', '>' (and their
|
||||
# corresponding '\e\C-a' bindings) may also be dropped if you don't need them.
|
||||
|
||||
# Regexes for (heuristically) determining whether we're abbreviating the first word.
|
||||
# Construction put into functions to prevent global namespace pollution
|
||||
|
|
@ -132,12 +133,14 @@ _try_abbrev () {
|
|||
# metacharacter
|
||||
# A character that, when unquoted, separates words. One of the following:
|
||||
# | & ; ( ) < > space tab newline
|
||||
# Note: double quote should be escaped, if added to the list of metacharacters
|
||||
for ch in ' ' '|' '&' ';' '(' ')' '<' '>'; do
|
||||
bind -x '"'"$ch"'": _try_abbrev "'"$ch"'"' # Note: double quote should be escaped, if added to the list of metacharacters
|
||||
bind -x '"\e\C-a'"$ch"'": _try_abbrev "'"$ch"'"'
|
||||
bind '"'"$ch"'": "\e\C-a'"$ch"'"'
|
||||
# bind '"'"$ch"'": "\e\C-a'"$ch"'\e^"' # Moves point weirdly
|
||||
done
|
||||
|
||||
# Newline must be treated specially by creating a new binding which is called
|
||||
# as a readline macro when pressing enter (C-m). After that is finished, the macro
|
||||
# continues with a regular C-j, which accepts (=executes) the line as you would expect.
|
||||
bind -x '"\e\C-a": _try_abbrev ""'
|
||||
bind '"\C-m": "\e\C-a\e^\C-j"'
|
||||
# Newline must be treated specially, because it doesn't self-insert
|
||||
# and has the extra functionality of accepting a line.
|
||||
bind -x '"\e\C-an": _try_abbrev ""'
|
||||
bind '"\C-m": "\e\C-an\e^\C-j"'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue