Zsh Mailing List Archive
Messages sorted by:
Re: An example of writing a custom history file?
- X-seq: zsh-users 19541
- From: Rocky Bernstein <rockyb@xxxxxxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Subject: Re: An example of writing a custom history file?
- Date: Mon, 15 Dec 2014 09:26:21 -0500
- Cc: zsh-users@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=oyeZUKdZpaEIkVAveyRHiE//mjTXo74uZDvbtANWDuQ=; b=PfIi9QUug3KhOmNdmQ6Yt//b3B+Rbn0bSFR4Ov9cclRAImthlgMWKEH/+0qRnOPUVn XFVSwC8hB4CIGbQAkLblPWkUhD2h6l6Ss8uynCm/Cilv7qZ4OmmDLm4JFm5AzHBaSJjE g9erPrJFWtoH0GNRAWuuNBVB3Bcjsyodw+FKamKyC8fjnpgcYQMRMDuxjD9nejNzQqxC 95TF+9dZp2SGaBZjm0z2MqjqKjh3Q0rgtm8ejaCfMyywWcl9jBmcgzxaOoK0lSFbSEvu PJywPq7oCJnGRH+uGyQY18sYyoH9ZDRW3I95tIBYnWkOiPm4ruYIYRDWbhRLPy1DAk2n XNWA==
- In-reply-to: <141215003717.ZM24212@torch.brasslantern.com>
- List-help: <mailto:email@example.com>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:firstname.lastname@example.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CANCp2gYQKgxOFb8FOP9KWRku68DVq=j9on1MH=bDmbdwAkewiQ@mail.gmail.com> <141214185332.ZM24112@torch.brasslantern.com> <CANCp2gYhs8S863OfkMb824QHPx0xPq2cYqJ_8sB8qd-2N91CHg@mail.gmail.com> <141215003717.ZM24212@torch.brasslantern.com>
- Sender: rocky.bernstein@xxxxxxxxx
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:
fc -ap /tmp/example_history 1000
# Read lines and add them to history
while vared -h -p "hey: " line
[[ $line == 'quit' ]] && exit 0
fc -p /tmp/example_history 1000
# The -s option below adds the line to the history
print -s $line
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>
> 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.
> } 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
> } or not to add this to the history.
> # Pseudo-code
> if this_line should be added to the history
> then print -sR "$this_line"
Messages sorted by: