diff mbox series

histedit: When editing, use `el_set` with `EL_PROMPT_ESC` rather than `EL_PROMPT`.

Message ID 20240823222319.6732-1-sebastien.peterson.boudreau@gmail.com (mailing list archive)
State Accepted
Delegated to: Herbert Xu
Headers show
Series histedit: When editing, use `el_set` with `EL_PROMPT_ESC` rather than `EL_PROMPT`. | expand

Commit Message

sebastien peterson boudreau Aug. 23, 2024, 10:23 p.m. UTC
As can be seen in the `man` page for `el_set`, using `EL_PROMPT_ESC` for
the op is the same as `EL_PROMPT`, but it allows escape characters to be
expanded in the prompt the same way they are when used with `echo` or
`printf(1)`.

As far as I know, this is not specified by POSIX, but neither is the
emacs editing mode (please correct me if I am wrong), so I think this is
a justified change to make it align with the behaviour or `echo` and
`printf(1)`.

Given that this is not specified by POSIX, there isn't much of a
precident for what the value of the start/stop character should be. From
what I have seen, 0o001 is common, so that is what I have included in
the patch, but it may not be the most fitting. Taking a look at how
ASCII defines its control characters, I believe any characters between
0o034 and 0o037 may be a more suitable choice, but this could be up for
debate.

Signed-off-by: Sebastien Peterson-Boudreau
<sebastien.peterson.boudreau@gmail.com>
---
 src/histedit.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Herbert Xu Nov. 16, 2024, 11:24 a.m. UTC | #1
sebastien peterson boudreau <sebastien.peterson.boudreau@gmail.com> wrote:
> As can be seen in the `man` page for `el_set`, using `EL_PROMPT_ESC` for
> the op is the same as `EL_PROMPT`, but it allows escape characters to be
> expanded in the prompt the same way they are when used with `echo` or
> `printf(1)`.
> 
> As far as I know, this is not specified by POSIX, but neither is the
> emacs editing mode (please correct me if I am wrong), so I think this is
> a justified change to make it align with the behaviour or `echo` and
> `printf(1)`.
> 
> Given that this is not specified by POSIX, there isn't much of a
> precident for what the value of the start/stop character should be. From
> what I have seen, 0o001 is common, so that is what I have included in
> the patch, but it may not be the most fitting. Taking a look at how
> ASCII defines its control characters, I believe any characters between
> 0o034 and 0o037 may be a more suitable choice, but this could be up for
> debate.
> 
> Signed-off-by: Sebastien Peterson-Boudreau
> <sebastien.peterson.boudreau@gmail.com>
> ---
> src/histedit.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)

Patch applied.  Thanks.
diff mbox series

Patch

diff --git a/src/histedit.c b/src/histedit.c
index 7692776..5ab718b 100644
--- a/src/histedit.c
+++ b/src/histedit.c
@@ -115,7 +115,7 @@  histedit(void)
 			if (el != NULL) {
 				if (hist)
 					el_set(el, EL_HIST, history, hist);
-				el_set(el, EL_PROMPT, getprompt);
+				el_set(el, EL_PROMPT_ESC, getprompt, '\1');
 			} else {
 bad:
 				out2str("sh: can't initialize editing\n");