zsh-users
 help / color / mirror / code / Atom feed
From: Rocky Bernstein <rockyb@rubyforge.org>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: zsh-users@zsh.org
Subject: Re: An example of writing a custom history file?
Date: Mon, 15 Dec 2014 09:26:21 -0500	[thread overview]
Message-ID: <CANCp2gaAnuFLuhWfzaTn0_KjX-VqsBHEZgGZ0M1U2w6Nw6C58A@mail.gmail.com> (raw)
In-Reply-To: <141215003717.ZM24212@torch.brasslantern.com>

[-- Attachment #1: Type: text/plain, Size: 1921 bytes --]

Almost there! The only remaining problem is now how write the accumulated
history. For that, I assume I use fc -W *filename* or fc -A *filename*. But
this isn't working. Here is the corrected simple program:

    #!/usr/bin/zsh
    fc -ap /tmp/example_history 1000

    local line
    # Read lines and add them to history
    while vared -h -p "hey: " line
    do
        [[ $line == 'quit' ]] && exit 0
        fc -p /tmp/example_history 1000
        # The -s option below adds the line to the history
        print -s $line
        line=''
    done
    fc -W /tmp/example_history

I have also tried putting "fc -A" as well and tried putting the write
command inside the loop.

Again, thank you.




On Mon, Dec 15, 2014 at 3:37 AM, Bart Schaefer <schaefer@brasslantern.com>
wrote:

> On Dec 15,  2:09am, Rocky Bernstein wrote:
> }
> } Thanks for the pointer. That program is too complicated and there is too
> } much going on for me to understand which parts add to the history file.
> I'm
> } guessing it has something to do with the
> } zle .push-line.
>
> Well, no, it doesn't have anything to do with that at all.
>
> } Here is the 138 line program boiled down to less than 10,  the parts I'd
> } like to focus on:
> }
> }     #!/usr/bin/zsh
> }     fc -ap /tmp/example_history 1000
> }     # Read lines and add them to history
> }     local sticky
> }     while vared -h -p "hey: "  sticky
> }     do
> }         print $sticky
> }         sticky=''
> }     done
>
> You've missed the important bit, which is the -s option to print.  THAT
> is what adds lines to the history.
>
> I probably should have pointed you to the example zshaddhistory hook in
> the documentation.
>
> } Additionally what I would like to do in the body of the loop decide
> whether
> } or not to add this to the history.
>
>     # Pseudo-code
>     if this_line should be added to the history
>     then print -sR "$this_line"
>     fi
>
>

  reply	other threads:[~2014-12-15 14:26 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-15  1:38 Rocky Bernstein
2014-12-15  2:53 ` Bart Schaefer
2014-12-15  7:09   ` Rocky Bernstein
2014-12-15  8:37     ` Bart Schaefer
2014-12-15 14:26       ` Rocky Bernstein [this message]
2014-12-15 16:14         ` Bart Schaefer
2014-12-15 17:05           ` Rocky Bernstein
2014-12-15 17:46             ` Peter Stephenson
2014-12-15 18:22             ` Mikael Magnusson
2014-12-16  3:58               ` Rocky Bernstein
2014-12-15 18:26             ` Bart Schaefer
2014-12-15 18:34               ` Mikael Magnusson
2014-12-16 11:36                 ` Peter Stephenson
2014-12-16  5:57               ` Rocky Bernstein

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CANCp2gaAnuFLuhWfzaTn0_KjX-VqsBHEZgGZ0M1U2w6Nw6C58A@mail.gmail.com \
    --to=rockyb@rubyforge.org \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).