From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 23940 invoked from network); 9 Feb 2021 05:32:23 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 9 Feb 2021 05:32:23 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1612848743; b=R+2AsoeDXwsenNCGX4zaxbSinc62KZXPIt/ASAs6DJ8NZeB/S4HTCKFlgox/kO1W12nuDCYgyj HS+9/u1b1hhmNEwHKMUxUHAmU2h4W5dgARluDEZpCarHyg8FzBUHLPNnqupeI1/vM49x1QGtwx ToTop8hZjbiP7n1M8DyHUh5NQ23vA2AM9e7FC1IACJfR07sV4F7/4XbXmOHsMHTxq5dxlS+mqt FTXBENc91+nvyrfdmLszCQyQFfGtM7gRLKnhTqUM5Ou8XzIr3t/VTjCUGq9iswRFCX/6cZ4XS/ 8ZfzNHbJZ9fygt5ERy4ifKscLR/2gmgkgxwb0/jDUwEi9Q==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-oi1-f174.google.com) smtp.remote-ip=209.85.167.174; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20200801; t=1612848743; bh=1bxvAp5uF2cypa9xSa4yD/slsPeqxM2tBUiepmbPGxs=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=CpC1E0vC1nKtIQ/Suetk5OXRvJ/fTBHusLzcU8S9Gm2rHKfa5cwGAeDSOTmRjowEtdOTf8fNnu nP8hdvfzQzN53EtjEBKpef8UGjAdXyPBqN02JcDljwGkBuauWOFTR85OAQXVFua/ZoLPpLYMB6 16S+oqIzcUarEbEsjlCuqm5QNLW+HWQ/hb9Lf1gJLrHBV2k0MxP8RBcSDxsCyr6cfC3GKUMHhQ PwxYS1RU3OTZ40+9229q9fI7zBNikrcvxC9O3d3wqEgRCS9A7/vpoM2dDliHTJCyrEKA5EkhsW HqCOzULGyDXarqacHWY7AyxEe76xljoEBxqOK+nqbk97xA==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=w8kFkD/TF4gSvoPnH34kHRAXcMY2TWr6Rl0Sq5PjnOk=; b=Rd/RXA7YBUKOq5XYCJgVbs/vdh AGvd0AWB16UyjYhWJGWCyPrFerx3L6zBpIBtyDIXz20xHqoXZZW8mQD4QOAkwX4brbI6TgLbPx/Y8 SYkk0f2p5B7cL8IYrTvKEC1kfDLTB6Q6pwBVaEUvedhDJ3jGEbaFzAIveJfWJf6pMWTnqBeyD1XGm KHFwVMMLplZtR9W/qQjso/PDb8Y8+zsHRU2ll+789RH/DQLjn6RIo4+3YL5kUbZTDnUkmFdFC8UkW c9YkRrzAhhPxOx79Qa8mu1ijTKWOQLrvb3NG55703B5zwO6kvkr+6Xcwgft7095/g8w7NDGNSYYb4 W9ofAVBw==; Received: from authenticated user by zero.zsh.org with local id 1l9LdN-000I8O-GR; Tue, 09 Feb 2021 05:32:21 +0000 Authentication-Results: zsh.org; iprev=pass (mail-oi1-f174.google.com) smtp.remote-ip=209.85.167.174; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-oi1-f174.google.com ([209.85.167.174]:35049) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1l9Ld6-000I0Q-In; Tue, 09 Feb 2021 05:32:05 +0000 Received: by mail-oi1-f174.google.com with SMTP id l3so8295338oii.2 for ; Mon, 08 Feb 2021 21:32:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=w8kFkD/TF4gSvoPnH34kHRAXcMY2TWr6Rl0Sq5PjnOk=; b=FXK0FrGld9uDCeY8lvs4OBsPafqiLzSfSq74f3w6JqDz4up73OaoWSWTCqNnnlEADF 9aMBDauiqIfhI2O5phic6ftqbLdlG0LkuUEtJhu0GGZ9O2Uk07istsHRUzUEuLBV56PH e8/Exw+HFcJaPKgDQYCdM4TvXk3fyTkE/LIFMKZfZtEQTyT8VaF+ha0CfFFee0z1jEC8 0jlxIjmWACBljoV9Vyx6XMDcMbCTov4770whQMPeYsDTBpqsaLf0LImtTgU+OsTIeYq6 eWq+0ZJyJLZdrNBFNobhifmiz/l675tvCIwRpgE5RJsO342OmnvtOthmJcBpcKbBFUAZ rZTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=w8kFkD/TF4gSvoPnH34kHRAXcMY2TWr6Rl0Sq5PjnOk=; b=raHiUr2bxGL0ExaU5sg6Oj+rni/zyZMjHyVjmo2rRwVE1nh1m7jJnm4kzhiqAKdh6N M5/SCu/8ekGljMSvdoLP8QVQWgbR2NjDqacm54zgV9rISoF0jSY8tg9gw2IwWBD4vhZl A5+Pmk/bsGFVt7o3v5CKPNdiPJviSrZgOkLx43ZtUf5WuUn/DpXjhPp1q7eDHlJFNUJr LERgTSrd34KUm0EZ05VLO5jXS9fVhjRxMUneTGcmVBXAKyzJEiNjJDMamPSfrsH7G2V0 faRbpkNzeu2ItQqvxf0EiTJKS0qxy2QI/TPEtUVO+F6LsZZM8mvtu7o2CqklNe1qeA7f giqQ== X-Gm-Message-State: AOAM5337AVTg1FsD96+UthQ4f5qHtjPwa9yeXcFy6G3w3kQx5M/mob4j 9inqDFT1cgoyIB3tVyVwZxEMDHI6b5BWwVAip/Ob/WBZ3XIOUg== X-Google-Smtp-Source: ABdhPJzgnY29X08iyU9662xhncbKQ1WZhTrn14TaUqAnwRy3dwqTL43sd7b6u7ubdc5TTwJgr7QRk6xGgoWRNBHejhE= X-Received: by 2002:aca:4e8e:: with SMTP id c136mr1456842oib.173.1612848723202; Mon, 08 Feb 2021 21:32:03 -0800 (PST) MIME-Version: 1.0 References: <24543.52705.896312.857217@lwm.klanderman.net> <877dp9omok.fsf@lwm.klanderman.net> <878s8yksp0.fsf@lwm.klanderman.net> <87sg662frk.fsf@lwm.klanderman.net> In-Reply-To: <87sg662frk.fsf@lwm.klanderman.net> From: Bart Schaefer Date: Mon, 8 Feb 2021 21:31:52 -0800 Message-ID: Subject: Re: additionally saving history for each directory? To: Greg Klanderman Cc: Zsh list Content-Type: text/plain; charset="UTF-8" X-Seq: 47962 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: Archived-At: On Mon, Feb 8, 2021 at 5:26 PM Greg Klanderman wrote: > > Figured I'd follow up with this on workers since I never got a > response on whether > > save_per_directory_history () { > setopt localoptions incappendhistory > fc -p -a .zsh_local_history 1000 > print -sr -- ${1%%$'\n'} > } > > should work in zshaddhistory_functions for saving local history. It doesn't work because you added the -a option to the fc command. A hook function may call 'fc -p ...' to switch the history context so that the history is saved in a different file from the that in the global HISTFILE parameter. This is handled specially: the history context is automatically restored after the processing of the history line is finished. (Hm, typo there, "from the that") The history file isn't actually written until the hooks have all finished running, because the exit status of the hook function can control whether the event gets written at all. "fc -p -a" closes the alternate history when the function returns, which is before the decision to write has been made, so nothing gets written. The other non-obvious (and not really documented) thing about using "fc -p" in the zshaddhistory hook is that it has to be the last line in the function. It appears from some prodding that you can follow it with another history hook function in zshaddhistory_functions, but if anything follows it in the same function, it doesn't work. I suspect this is unintentional, but it seems to be the reason that the documentation has the example in the order that it does: zshaddhistory() { print -sr -- ${1%%$'\n'} fc -p .zsh_local_history } Further, even if you put the "fc -p" before the "print -s", the hook magic causes the line to be added to the original internal history rather than to a new list created by "fc -p", so "fc -AI" or similar have nothing to write into .zsh_local_history. The only way to do it is to use "fc -p" without "-a" and as the last command in the function. And, I suspect although I got a bit lost trying all the permutations, incappendhistory has to be a global setopt rather than a local one, again because the local scope has already ended before the write decision is made.