Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix keyseq specification in Bash #426

Merged
merged 1 commit into from
Jul 12, 2024
Merged

Conversation

akinomyoga
Copy link
Contributor

@akinomyoga akinomyoga commented Jul 11, 2024

The current way of setting the keyseq as bind "'\C-r': '...'" appears to work as expected, but this is accidental. This is not the format that Readline supports; the keyseq cannot be enclosed within single quotes. This is now working because of Readline's loose treatment of the keyseqs, but this will easily be broken with a slightly different key representation.

Readline's interpretation of '\C-r' is as follows:

  1. This doesn't start with the double quote, so Readline considers a legacy specification for a single key.
  2. Readline splits the string with hyphens to extract the unmodified key name: r'. This doesn't match any known key names such as ESC, DEL, etc., so Readline just picks up the first character r.
  3. To obtain the set of modifiers, Readline searches for C- and M- against '\C-r'. Now C- matches.
  4. As a result, Readline generates the key "C-" plus "r", which accidentally matches the intended one.

However, this doesn't work e.g. with a different representation of C-r: '\x12'. This time, the string doesn't contain a hyphen, so
Readline considers '\x12' is the full key name. It doesn't match any known key name, so Readline extracts the first character ' as the key, which is different from the intention. One can confirm this interpretation by the following commands:

$ bind "'\x12': 'hello'"; bind -s
"'": "hello"        # <-- We here expect "\C-r" but it's instead interpreted as a single-quote character
$ bind '"\C-r": "hello"'; bind -s
"\C-r": "hello"     # <-- "\C-r" works as expected.
"'": "hello"

In this PR, I suggest using the standard " instead of unsupported '. I modified it by reversing ' and ". The macro string (i.e., the righ-hand side of :) can actually be quoted by single quotes, but I also modified it to " because it is easier for quoting.

The current way of setting the keyseq as « bind "'\C-r': '...'" ≫
appears to be working as expected, but this is accidental.  This is
not the format that Readline supports; the keyseq cannot be enclosed
in single quotes.  This is now working because of Readline's loose
treatment of the keyseqs, but this will easily be broken with a
slightly different key.
@cantino cantino merged commit 5a16ee7 into cantino:master Jul 12, 2024
19 checks passed
@cantino
Copy link
Owner

cantino commented Jul 12, 2024

Thank you!

@akinomyoga akinomyoga deleted the bash-keyseq branch July 12, 2024 03:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants