#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/
|
# put into the bashrc drop-in directory ~/.bashrc.d/
|
||||||
# and then sourced from ~/.bashrc.
|
# and then sourced from ~/.bashrc.
|
||||||
|
|
||||||
# WARNING: This plug-in creates a new readline binding: '\e\C-a'
|
# WARNING: This plug-in overwrites the readling bindings for ' ', '|', '&', ';', '(', ')', '<', '>'
|
||||||
# and overwrites the binding for '\C-m', ' ', '|', '&', ';', '(', ')', '<', '>'
|
# 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.
|
# 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
|
# You may change the '\e\C-a' binding-"prefix" to whatever you want as it's only used
|
||||||
# as a hook inside another readline macro. The bindings '|', '&', ';', '(', ')', '<', '>'
|
# as a hook inside other readline macros. The bindings '|', '&', ';', '(', ')', '<', '>' (and their
|
||||||
# may also be dropped if you don't need them.
|
# 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.
|
# Regexes for (heuristically) determining whether we're abbreviating the first word.
|
||||||
# Construction put into functions to prevent global namespace pollution
|
# Construction put into functions to prevent global namespace pollution
|
||||||
|
|
@ -132,12 +133,14 @@ _try_abbrev () {
|
||||||
# metacharacter
|
# metacharacter
|
||||||
# A character that, when unquoted, separates words. One of the following:
|
# A character that, when unquoted, separates words. One of the following:
|
||||||
# | & ; ( ) < > space tab newline
|
# | & ; ( ) < > space tab newline
|
||||||
|
# Note: double quote should be escaped, if added to the list of metacharacters
|
||||||
for ch in ' ' '|' '&' ';' '(' ')' '<' '>'; do
|
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
|
done
|
||||||
|
|
||||||
# Newline must be treated specially by creating a new binding which is called
|
# Newline must be treated specially, because it doesn't self-insert
|
||||||
# as a readline macro when pressing enter (C-m). After that is finished, the macro
|
# and has the extra functionality of accepting a line.
|
||||||
# continues with a regular C-j, which accepts (=executes) the line as you would expect.
|
bind -x '"\e\C-an": _try_abbrev ""'
|
||||||
bind -x '"\e\C-a": _try_abbrev ""'
|
bind '"\C-m": "\e\C-an\e^\C-j"'
|
||||||
bind '"\C-m": "\e\C-a\e^\C-j"'
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue