From 91600446c6fc2f9101b279a4c6d4e9ce57388f78 Mon Sep 17 00:00:00 2001 From: tsi Date: Tue, 21 Oct 2025 00:45:06 +0200 Subject: [PATCH] #1: Allow history expansion on metacharacter insertion (currently disabled because it moves the point) --- bash-abbr | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/bash-abbr b/bash-abbr index 5a15319..e3dc6fa 100644 --- a/bash-abbr +++ b/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' where `` 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"'