Re: Do a readline function execution inside bash

2020-09-15 Thread Chet Ramey
On 9/14/20 9:57 PM, Budi wrote:
> simply run a readline function among lines codes of bash script such a
> menu-complete, or menu-complete repeated thrice, or etc etc

In this model, where would readline get its data? Readline functions
operate on pieces of an input line, or an entire input line, so where
would this line come from?

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/



Re: Do a readline function execution inside bash

2020-09-14 Thread Koichi Murase
2020-09-15 10:59 Budi :
> simply run a readline function among lines codes of bash script such
> a menu-complete, or previous-history repeated thrice, or etc

What is not clear is not how you call the readline function, but what
kind of ``script'' do you assume?

a. If it is the normal executable script which can be used as
  `./script.sh', the question doesn't make sense because there is no
  command line and no readline.  Readline is only enabled in an
  interactive session of Bash.  So one can guess that you are either
  asking how to enable the readline in a script, or talking about some
  other type of scripts that you haven't explained.

b. If you want to enable readline and accept user inputs, you can use
  `read -e' as Greg wrote.  If you want to control the detailed
  behavior of `read -e' (i.e., how it behaves for each keystroke) by
  Bash scripts, the answer is it's impossible.

c. Maybe you are thinking of sourcing a script in an interactive
  shell, such as

  $ source script.sh

  In this case, it is still unclear what you want to do because the
  readline is inactive on the command execution.  There is no prompt
  or command line when the user command is executed.

d. Another possibility is that you are talking about the shell
  commands executed in `bind -x '"keyseq":unix-command''.  In this
  case, it is impossible to invoke a readline function directly from
  the shell commands.  But some limited class of mixed operations can
  be implemented by combining the `bind '"...":"..."'` macro.

e. Or maybe you are thinking of a completely different type of
  ``script''?

--
Koichi



Re: Do a readline function execution inside bash

2020-09-14 Thread Lawrence Velázquez
> On Sep 14, 2020, at 9:59 PM, Budi  wrote:
> 
> simply run a readline function among lines codes of bash script such a
> menu-complete, or previous-history repeated thrice, or etc

That doesn't really answer Greg's question. What larger task are
you trying to accomplish by invoking readline functions in this
way?

vq

P.S. Again, this is not really appropriate for bug-bash@gnu.org.
Please send these sorts of questions to help-b...@gnu.org instead.



Re: Do a readline function execution inside bash

2020-09-14 Thread Budi
simply run a readline function among lines codes of bash script such a
menu-complete, or previous-history repeated thrice, or etc

On 9/15/20, Budi  wrote:
> simply run a readline function among lines codes of bash script such a
> menu-complete, or menu-complete repeated thrice, or etc etc
>
> On 9/14/20, Greg Wooledge  wrote:
>> On Mon, Sep 14, 2020 at 10:09:16PM +0700, Budi wrote:
>>> How to do a readline function execution inside bash script as mimic to
>>> actual key press ?
>>
>> Please tell us what you're actually trying to do.  It makes a huge
>> difference.
>>
>> You said "script", so I guess you don't want to pre-populate the input
>> buffer of an interactive shell.  That would be one goal, and we could
>> tell you how to do that, but if it's not what you want, that would be
>> a waste of time.
>>
>> Perhaps you want to pre-populate the user's response to a prompt written
>> by the script, for a read command.  That's pretty easy: you just have to
>> tell read to use readline (-e), and then supply an initial response (-i).
>>
>> read -r -e -i "$LOGNAME" -p "Who are you? " who
>>
>> If that's not what you want, then we need to know what you *do* want.
>>
>



Re: Do a readline function execution inside bash

2020-09-14 Thread Budi
simply run a readline function among lines codes of bash script such a
menu-complete, or menu-complete repeated thrice, or etc etc

On 9/14/20, Greg Wooledge  wrote:
> On Mon, Sep 14, 2020 at 10:09:16PM +0700, Budi wrote:
>> How to do a readline function execution inside bash script as mimic to
>> actual key press ?
>
> Please tell us what you're actually trying to do.  It makes a huge
> difference.
>
> You said "script", so I guess you don't want to pre-populate the input
> buffer of an interactive shell.  That would be one goal, and we could
> tell you how to do that, but if it's not what you want, that would be
> a waste of time.
>
> Perhaps you want to pre-populate the user's response to a prompt written
> by the script, for a read command.  That's pretty easy: you just have to
> tell read to use readline (-e), and then supply an initial response (-i).
>
> read -r -e -i "$LOGNAME" -p "Who are you? " who
>
> If that's not what you want, then we need to know what you *do* want.
>



Re: Do a readline function execution inside bash

2020-09-14 Thread Greg Wooledge
On Mon, Sep 14, 2020 at 10:09:16PM +0700, Budi wrote:
> How to do a readline function execution inside bash script as mimic to
> actual key press ?

Please tell us what you're actually trying to do.  It makes a huge
difference.

You said "script", so I guess you don't want to pre-populate the input
buffer of an interactive shell.  That would be one goal, and we could
tell you how to do that, but if it's not what you want, that would be
a waste of time.

Perhaps you want to pre-populate the user's response to a prompt written
by the script, for a read command.  That's pretty easy: you just have to
tell read to use readline (-e), and then supply an initial response (-i).

read -r -e -i "$LOGNAME" -p "Who are you? " who

If that's not what you want, then we need to know what you *do* want.



Do a readline function execution inside bash

2020-09-14 Thread Budi
How to do a readline function execution inside bash script as mimic to
actual key press ?