zsh-users
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: An example of writing a custom history file?
Date: Mon, 15 Dec 2014 19:34:52 +0100	[thread overview]
Message-ID: <CAHYJk3Sk4ae8suGWMLU7Wm=vAQbMFUJp0sa1DOPTWA0vgY0r4g@mail.gmail.com> (raw)
In-Reply-To: <141215102652.ZM25198@torch.brasslantern.com>

On Mon, Dec 15, 2014 at 7:26 PM, Bart Schaefer
<schaefer@brasslantern.com> wrote:
> On Dec 15, 12:05pm, Rocky Bernstein wrote:
> }
> } Making the change suggested, adding 1000 doesn't change the behavior - no
> } file is written. Again, here is the entire 12-line 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
> }         # The -s option below adds the line to the history
> }         print -s $line
> }         line=''
> }     done
>
> This worked for me exactly as written; I got lines saved in the
> /tmp/example_history file.  However, I was working with an interactive
> shell, which normally saves history at exit.  If you are trying to run
> this as a stand-alone script, you probably don't want "exit 0" there.
> More likely you just want to "break" and let the loop finish.  Also
> if running standalone, there's no "function scope" so I suspect that
> foils the usual action of "fc -a".
[...]

I tried the script with and without -a and a -P at the end, and
nesting the body inside a () { } anon function, nothing "helps" in the
case of a non-interactive shell, and with an interactive shell, none
of it is needed.

I found only one place in the manpage that mentions history only being
active in an interactive shell, perhaps it should be clearer about it?
I also noticed that explicit fc -l and fc -W etc do nothing but also
don't print a warning when invoked non-interactively.

HISTFILE
  The file to save the history in when an interactive shell
  exits. If unset, the history is not saved.

I think before we added print -s, there was no way to get history
non-interactively (I suppose fc -R?) and likely nobody thought to
mention the restriction in the fc docs when adding it?

-- 
Mikael Magnusson


  reply	other threads:[~2014-12-15 18:34 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
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 [this message]
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='CAHYJk3Sk4ae8suGWMLU7Wm=vAQbMFUJp0sa1DOPTWA0vgY0r4g@mail.gmail.com' \
    --to=mikachu@gmail.com \
    --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).