bug-bash
[Top][All Lists]
Advanced

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

read -E with read -d in completion function


From: Grisha Levit
Subject: read -E with read -d in completion function
Date: Mon, 21 Aug 2023 17:50:25 -0400

The new read -E option is a nice addition.
I think it's not unreasonable for a completion function to itself invoke
`read' (with a file or pipe as input, not a tty) and this mostly works out
fine, unless the -d option is used since the builtin stores the delimiter
arg in a static variable:

$ f() { read -dX </dev/null; }
$ complete -F f f
$ read -E
f ^I^M
$ # \C-m no longer bound to accept-line

Seems like it can be changed to a local one and then the above works fine.
---
 builtins/read.def | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/builtins/read.def b/builtins/read.def
index 1c528deb..8817cc64 100644
--- a/builtins/read.def
+++ b/builtins/read.def
@@ -123,7 +123,7 @@ struct ttsave
 #if defined (READLINE)
 static void uw_reset_attempted_completion_function (void *);
 static int set_itext (void);
-static char *edit_line (char *, char *, int);
+static char *edit_line (char *, char *, unsigned char, int);
 static void set_eol_delim (int);
 static void reset_eol_delim (void *);
 static void set_readline_timeout (sh_timer *t, time_t, long);
@@ -144,8 +144,6 @@ static void uw_reset_timeout (void *);
 sh_timer *read_timeout;

 static int reading, tty_modified;
-static unsigned char delim;
-
 static struct ttsave termsave;

 /* In all cases, SIGALRM just sets a flag that we check periodically. This
@@ -225,6 +223,7 @@ read_builtin (WORD_LIST *list)
   long ival, uval;
   intmax_t intval;
   char c;
+ unsigned char delim;
   char *input_string, *orig_input_string, *ifs_chars, *prompt, *arrayname;
   char *e, *t, *t1, *ps2, *tofree;
   struct stat tsb;
@@ -266,6 +265,7 @@ read_builtin (WORD_LIST *list)
   USE_VAR(list);
   USE_VAR(ps2);
   USE_VAR(lastsig);
+ USE_VAR(delim);

   reading = tty_modified = 0;
   read_timeout = 0;
@@ -660,7 +660,7 @@ read_builtin (WORD_LIST *list)
    if (rlbuf == 0)
      {
        reading = 1;
- rlbuf = edit_line (prompt ? prompt : "", itext, use_bash_completion);
+ rlbuf = edit_line (prompt ? prompt : "", itext, delim,
use_bash_completion);
        reading = 0;
        rlind = 0;
      }
@@ -1208,7 +1208,7 @@ set_itext (void)
 }

 static char *
-edit_line (char *p, char *itext, int keep_completion_func)
+edit_line (char *p, char *itext, unsigned char delim, int
keep_completion_func)
 {
   char *ret;
   size_t len;
-- 
2.41.0


reply via email to

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