bug-bash
[Top][All Lists]
Advanced

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

Re: Bash - various feature requests


From: Richard Neill
Subject: Re: Bash - various feature requests
Date: Fri, 29 Dec 2006 23:19:36 +0000
User-agent: Thunderbird 1.5.0.8 (X11/20061115)


5)An enhancement to read/readline, such that one can specify the initial value with which the buffer is filled.

Currently, we can do:

  read -ep 'Enter your name: ' NAME

and I might type "Richad Neill".      #Note the deliberate typo.

If the script recognises this as invalid, the best it can do is:

  echo "Name not recognised"
  read -ep 'Re-enter your name: ' NAME

and the user must retype it in full.
I'd like to propose adding an "-i" option for initial value:

  echo "Name not recognised"
  read -ep "Please correct your name: " -i "$NAME"

The shell prints:
  Please correct your name: Richad Neill
where the latter part is now editable.

Thus the really nice editing features of readline can be used for updating values already stored in variables. This is extremely useful when the value is quite long.

Is this the same as
    read -ep "Please correct your name: $NAME" NAME
?


No - that isn't what I meant. What I want to do is:
   1)Print the text:
                "Please correct your name: "
        without a trailing newline.

   2)Create an editable buffer (using readline), which is initialised
     with the current value of the variable $NAME and printed to screen.

3)The user edits the buffer as desired, and when he presses ENTER, its contents is assigned to the variable NAME.


In the example I gave, with my proposed -i option, the script would present the user with this:

    Please correct your name: Richad Neill
                              ^^^^^^^^^^^^*

the cursor position starts at the *, but can be moved around anywhere within the ^^^^. So the typo could be corrected by keying:

Alt-B  Ctrl-B, Ctrl-B, r, ENTER


whereas currently, the user must type in the full string from scratch.



Is that clear? Sorry it's hard to explain without a diagram.

Richard







reply via email to

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