From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id 6A4542585D for ; Fri, 15 Mar 2024 13:48:24 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1710506904; b=l5qSdsuh5Uxd5+XIMMN9Fwt87iwIBePZkegak7TYZ6jWphnrab2l+YIjtt3m0bjd32ir+TGQDT LmoaR+Vb8NPUiQ77w+7olfCI8YMyikTvRpv+ny42gFwcnAfuHjQzGaYYpD9TUJqt+hckcdDb5t aYO9QTMVKhENfcVapdif0vwXwWqChsFeMq9SbZ1W9L7j0AckFuoRAf0UENDABawf60JxXM4ZjL +H7RHKTBGp23/LnSpLfbLcye0YpVaWJG1Qz23jxwXrgxC6h5lSGH4uPppjSQBhoboNPKceP9VV PWjHIbONvEjPWPdY9QVn/I8n6ox8TkP7+ac/gx8RRlOWIg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (cventin.lip.ens-lyon.fr) smtp.remote-ip=140.77.13.17; dmarc=none header.from=vinc17.net; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1710506904; bh=WBRGUZvwVd6tsxIX0vz+XWOJN+80rFK9KWSKxf+o1Lc=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Message-ID:Subject:To:From:Date:DKIM-Signature; b=h1Wqr7sUzKVRy1vb4dh7GYNElkSAsMux9gNSJj6dUGUJinfEc+LvTXxAshiCWViVEU9yNYN6eX QV/VcxYaz1Ay/Dw3NsjxlLmnzgAXxl2M3CbsaYTohihFyPOPg5M0VXatOS5SgBCHbpUz1niuEL hnjN/pfExfBiLxrEXSLqHwE9T/sbTQBwZpk+idNF5SkNserKP8RbvoX36vTD3FKPvOQqyVGkJS 9UGUjjIHKXlSqh+lGKBWWO4rlkGqEkpnUJ9kxjN+Cjduc//rf7jdMvJ09RP1dihyGDtOpz+Lfv bud5EpI+aSUknhgAkXfN3rVmtAxcyTbyNmLpLrlKe62D7g==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:In-Reply-To:Content-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:To:From:Date: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=Y037NHS0CNalICb4/7ybamz/AEIvSb4D7GOn81PwYGE=; b=HVuFApPg34qJ3GoJg4bv1HM/Yl U+3E312cIFEp10MFqJfAMao+pMU6zmpas+0ABPbszGzaTAlY9ShQEQr/ev+6s9RQyl3M4Mcmre8g1 nfiNwTfhkaQ3h8Uwfg8ZklvnvtMnWmdKLgQ2BlhlUJA89Zl5UFTommLKZjvyAMirGE7/M5sz+cMKp kOBmIqr44w9Q6ntd37yatFYAAJ8jXzb8OS0T243UK/EeTlqjAc7FwEQlS2TLxqKWw4++OE5q4BKTD uXGle79Pce1hdnAdfJ+QKdOZXcxWIIwJuUIrdG4Ri9/qr1btscTmEj3UM9T6EQuZMK0cEuBauMA+U r0sKTKSg==; Received: by zero.zsh.org with local id 1rl6z2-0004rF-N0; Fri, 15 Mar 2024 12:48:24 +0000 Authentication-Results: zsh.org; iprev=pass (cventin.lip.ens-lyon.fr) smtp.remote-ip=140.77.13.17; dmarc=none header.from=vinc17.net; arc=none Received: from cventin.lip.ens-lyon.fr ([140.77.13.17]:53662) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1rl6yU-0004XK-Ey; Fri, 15 Mar 2024 12:47:51 +0000 Received: from vlefevre by cventin.lip.ens-lyon.fr with local (Exim 4.97) (envelope-from ) id 1rl6yU-0000000FhUn-0wKu; Fri, 15 Mar 2024 13:47:50 +0100 Date: Fri, 15 Mar 2024 13:47:50 +0100 From: Vincent Lefevre To: zsh-workers@zsh.org Subject: Re: issues with saving history to file Message-ID: <20240315124750.GB3738413@cventin.lip.ens-lyon.fr> Mail-Followup-To: zsh-workers@zsh.org References: <20240313150511.GA3498572@cventin.lip.ens-lyon.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Mailer-Info: https://www.vinc17.net/mutt/ User-Agent: Mutt/2.2.12+69 (354c5b11) vl-149028 (2023-12-10) X-Seq: 52762 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: On 2024-03-13 21:52:44 -0700, Bart Schaefer wrote: > On Wed, Mar 13, 2024 at 8:05 AM Vincent Lefevre wrote: > > IMHO, HISTFILE should just be unset by default; but if the user sets > > this parameter, I suppose that the goal is to save the history. > > The goal might be to read the history, not to write it. To read the history? The zshparam(1) man page just says "to save": HISTFILE The file to save the history in when an interactive shell exits. If unset, the history is not saved. And when I do cventin:~> zsh -f cventin% HISTFILE=~/.histfile I just get the "HISTFILE=~/.histfile" in the history, while ~/.histfile already contains various commands. > > Without INC_APPEND_HISTORY, the man page doesn't document when > > precisely the history is saved. For instance, what happens if one > > has a "print -s ..." in the .zlogout file? > > It'd expect it to be lost, because the history is saved before > .zlogout is read. Try it and let us know. Maybe it dumps core. It is added to the history, but not saved. With ls -l .histfile sleep 1 print -s foo1 print -s foo2 print -s foo3 history ls -l .histfile in my .zlogout file, I get -rw------- 1 vlefevre vlefevre 292 2024-03-15 13:17:11 .histfile [...] 27 foo1 28 foo2 29 foo3 -rw------- 1 vlefevre vlefevre 292 2024-03-15 13:17:11 .histfile and indeed, .histfile does not contain these lines. > > Moreover, with INC_APPEND_HISTORY, "print -s" does not put the entry > > in the history file immediately, only after the next accept-line. > > "print -s" doesn't write to the HISTFILE and isn't documented that > way. It explicitly says "Place the results in the history list". The > "history list" is the internal shell history, not the file. The file > is updated from the internal list either at shell exit or > (incappendhistory) when a line is entered (i.e., conceptually upon > accept-line, though in practice upon entering a complete command since > updating at PS2 would leave an incomplete entry). The documentation is not explicit. > You can use the zshaddhistory hook to confirm this. The documentation of the zshaddhistory hook is not clear. It says Executed when a history line has been read interactively, But this is the case for any (possibly empty!) command line, not just lines read from the history. Then but before it is executed. This is wrong. Empty command lines (which will not be executed) are also handled by the zshaddhistory hook (contrary to the preexec hook). And as a consequence, its example zshaddhistory() { print -sr -- ${1%%$'\n'} fc -p .zsh_local_history } has the effect to put empty command lines in the history, which is not the usual behavior. Moreover, the "fc -p .zsh_local_history" does not seem to work: no .zsh_local_history file is created. -- Vincent Lefèvre - Web: 100% accessible validated (X)HTML - Blog: Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)