Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: fc in non-interactive shells and vared



On Fri, Oct 26, 2007 at 02:27:39PM +0100, Peter Stephenson wrote:
> Stephane Chazelas wrote:
> >   - I could not use fc to load/save a history file as fc refuses
> >     to work in non-interactive shells. Instead, I have to create
> >     a history file manually, read it line by line and use print
> >     -s to build the history stack.
> > 
> >     Is there a better way around that?
> 
> You can force a script to be run in interactive mode by including "-i"
> in the options to the shell.  This may have side effects, however.

Ok, thanks Peter, I will try that.

> >   - When "vared" returns, zsh prints a NL character. As I'm on
> >     the last line of the screen, this causes the screen to
> >     scroll. Is there any way to avoid that? I tried to do a stty
> >     onlret, but that doesn't work as vared resets the termios
> >     settings.
> 
> I suspect this is coming from the trashzle() when ZLE exits.  This is
> quite well buried.
> 
> I'm too lazy to try it, but if you have a sufficiently recent zsh you
> could try something like
> 
> zle-line-init() { stty onlret; }
> zle -N zle-line-init
[...]

I realised it wouldn't work anyway, I had misinterpreted what
onlret was doing. I just found another work around, I do
something like:

  accept-and-bye() {
    print -r -- "$BUFFER"
    stat +link -A pid /proc/self
    trap - TERM
    kill $pid
  }
  zle -N accept-and-bye
  bindkey '\r' accept-and-bye
  bindkey '\n' accept-and-bye
  a=
  search=$(vared -p "Search: " -eh a)

The /proc/self above makes it Linux specific though (exit
doesn't work: NL is still displayed).

I'll do more experiments by running zsh -c so that I can use $$.

-- 
Stéphane



Messages sorted by: Reverse Date, Date, Thread, Author