From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25590 invoked by alias); 15 Dec 2014 18:34:57 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 19548 Received: (qmail 16846 invoked from network); 15 Dec 2014 18:34:56 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=NDs4RHnEzaGhPaf1jms9ZjTen63h4x8hQDEFQL+OnPw=; b=bs7neKRChrwWl2QzzLHVNM2F0VBUotkS/oScyEaDOR6A5/IEceXlHB7Gb6QHU5Bmbi A+Owl5WH/kuyvH0eicO3pRKQ/mkLD3CwIBANP9oU1MrhOB03KCsxOpOMDK+LFAJdb1IL cS1VPDlvRlCi6kUzVSk7hlMzgObQvCZkTFGzzyy8WUXTQNHsBIPI1Y1dGeKRs0nlM7nG tPCBjQUw6guP7WD9q3K5bODwobwV5D4Y9ySpZg2ibLiwMEc73qpDroK+DHkjbiA3SOtM Yi9XROiD4d7jTPrCqlmfEXfFiHq+H4nIHBLT4Qxu4Ih/FauxcK6u13UICwTW0bhEpz3j INTw== MIME-Version: 1.0 X-Received: by 10.107.130.197 with SMTP id m66mr30534295ioi.10.1418668492954; Mon, 15 Dec 2014 10:34:52 -0800 (PST) In-Reply-To: <141215102652.ZM25198@torch.brasslantern.com> References: <141214185332.ZM24112@torch.brasslantern.com> <141215003717.ZM24212@torch.brasslantern.com> <141215081440.ZM25053@torch.brasslantern.com> <141215102652.ZM25198@torch.brasslantern.com> Date: Mon, 15 Dec 2014 19:34:52 +0100 Message-ID: Subject: Re: An example of writing a custom history file? From: Mikael Magnusson To: Bart Schaefer Cc: Zsh Users Content-Type: text/plain; charset=UTF-8 On Mon, Dec 15, 2014 at 7:26 PM, Bart Schaefer 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