bug-bash
[Top][All Lists]
Advanced

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

Re: Bash/readline enhancement: wish to pre-set initial value of input te


From: Richard Neill
Subject: Re: Bash/readline enhancement: wish to pre-set initial value of input text
Date: Tue, 08 Jul 2008 06:06:35 +0100
User-agent: Thunderbird 2.0.0.12 (X11/20080306)

Jan Schampera wrote:
> Richard Neill wrote:
>> Dear All,
>>
>> When using read, it would be really neat to be able to pre-fill the form
>> with a default (or previous) value.
>>
>> For example, a script which wants you to enter your name, and thinks
>> that my name is Richard, but that I might want to correct it.
>> Alternatively, this would be useful within a loop, to allow correction
>> of previously-entered text, without fully typing it again.
> 
> A bit of the functionality (in some way) is already there. You can
> preload the commandline history and use read -e:
> 
> --snipsnap--
> If -e is supplied and the shell is interactive, readline is used to
> obtain the line.
> --snipsnap--
> 
> A bit of hard work, though.
> 

I do have a sort of workaround, namely to put the default value on the
clipboard, by using:


function copy_to_clipboard () {         
        #If we're running KDE, put the text into klipper.
        #Else, use xclip.  Fail silently if we can't do it.
        { dcop klipper klipper setClipboardContents "$1" ||  echo "$1" |
         xclip ; } > /dev/null 2>&1
}

copy_to_clipboard INITIAL_VALUE
read -e -p "Enter name" NAME
#User must middle-click

but this is rather ugly, as well as only semi-functional. What I want to
do is just to pre-fill readline's buffer, before it gets presented to
the user.

I also tried to hack something nasty out of xmacroplay, but that doesn't
work.


Richard






reply via email to

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