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

Re: An example of writing a custom history file?



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@xxxxxxxxxxxxxxxx>
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
>
>


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