bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: About `M-C-e` expand result `'` failed


From: Martin D Kealey
Subject: Re: About `M-C-e` expand result `'` failed
Date: Sun, 4 Feb 2024 18:04:07 +1000

On Sat, 3 Feb 2024 at 07:21, Chet Ramey <chet.ramey@case.edu> wrote:

> On 2/2/24 3:36 PM, Zachary Santer wrote:
> >  Ultimately, what I'm saying is that a different bindable function that
> performs all the shell expansions other than quote removal would be more
> useful than shell-expand-line.
>
> OK, I'll take that as a feature request for a future version.
>

If I might make some related feature requests;
1. Please can the "strip quotes" functionality be its own separate bindable
function;
2. Please make the re-quoting  smart enough to handle "!" when history
expansion is enabled;
3. Please apply re-quoting after history expansion when histreedit is in
effect, so that '!' resulting from a history expansion doesn't trigger
*another* history expansion.

As I detailed earlier ...

> By all means, add a "strip-quotes" command to readline, so the user can
> use in the exceptional cases where you want to diverge from what the shell
> would have done without M-C-e, but by default any expansion or substitution
> that's triggered by a readline command should render a result that's immune
> to that same expansion being done again when the user hits enter.
>
> Which quotes to reinstate probably depends on which expansions have
> already been done. This includes history expansion when histreedit is on;
> for example, this is unhelpful:
>
> $ ! echo Hi
> Hi
> $ echo !:0!$
> [expands history and re-loads input buffer]
> $ echo !Hi
> bash_5.1.4p47-release: !Hi: event not found
>
> I suggest that the history expansion should note the result of an
> expansion includes a history expansion character ("!" by default), and
> apply a modification if it would be recognized as such (followed by
> [[:alnum:]_:?%*$-], and not in single quotes).
>
> That modification would be:
>  - outside quotes, insert \ before a recognized history character; if
> necessary mark this '\' byte to prevent it from being doubled by subsequent
> expansions
>

(it's not clear to me whether this can actually occur, but I raise the
issue so it doesn't get overlooked if it is actually necessary)


>  - inside single quotes, leave alone;
>  - inside double quotes, insert "" (two double-quote characters) after it.
>
> Similar safeguards would be needed after any other kind of expansion,
> except that it suffices to treat "!" as a
>
[generic meta-character]

> character for the purpose of deciding whether or not a word needs to be
> re-quoted. (As long as it's always single-quoted, or backslash-escaped, the
> history characters don't need any other special treatment.)
>
> One way to decide whether any history chars need protection would simply
> be to apply history expansion to the result of the requested expansion, and
> if that changes the text, something in it needs protecting. Ideally the
> history expansion logic would note the location of any history expansion
> characters, so that readline could use that as a hint of what to fix.
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]