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.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 12411 invoked from network); 13 Feb 2023 08:19:49 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 13 Feb 2023 08:19:49 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1676276390; b=Dpd7j552DNFwAL7Twy3TAYr+Yh5x8mjPS1gXyf6Vh670REkfPGi7iboJDtnIU0moxUreR/uIdN GBcODRjCusay++qCp3MBITpc0w3hcLR6X8tL/vXgYGf5d5wBNozqcBCkvSx7ADT7mzc8jKMqbQ sdK+w2Mte0QaB6A6m/yByLJImSyO+qXH5qT9rYb/Ehc2xumpF25rnA12gP5X7VtVBNqN/TX/ZL h7toruhwWNQk0JexSxexoylJeNzc8CJpMV+b0TYyhg+FnzJtP5fJ10ED6V6dJ/zgRjpdvo2Ev7 V/t/cdcZGeSHnJrv0cvz84yv3kkS3SpMUW0z7NL91fyTUw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lf1-f52.google.com) smtp.remote-ip=209.85.167.52; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1676276390; bh=u/1ASZsDZ+ovXSdD5dJGnV07lL4mddCvOSVOVimmvYE=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:Cc:To:Subject: Message-ID:Date:From:In-Reply-To:References:MIME-Version:DKIM-Signature: DKIM-Signature; b=EsoZKYYo08zU/e2TnwqUvJl69qj5tqFr9RDZIlMlBftGdttWbt/W1jPwT6MiCuRSQW8UmY5jYs iFucSF68onOonuvuGvMvfDhKz953qVFsDFdEesIZd39fCD2/gOHLb9iUcQ1FhMym0g59b6LS24 UWVbfdMUd3XT7ZDMAwrNQVwGiKp+WJUn73jEnxYcVMALcMK+ETBqmpFrlMoB7BUaAl+x4LKkf7 hvSCnXy76QxlhtF9SUybFaI92XnSoita7M4iQ6xWn0iaeIJIqhBp967N2r+xKfFHsNMiu5+CTb x3uqR5oseM1Z5sDg/hOscmfNUJ1GOSyAgDnGBMCnBuTk9g==; 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:Content-Transfer-Encoding: Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To:References: MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=Sa6rYSIN2lfP8soq21sLhsXlq7e+6H/O54WbQrfjK98=; b=fqJrQp65tu2TUGiqzv6A5rPHSD 6PpkgoUJpxDFzoH5yixWlvvIy3E8JY7SYGAa4QOm0pO7mR/sfy5Fa6cZrW6hyCPVvAS5Wmd01gQJk TJzr8mXZKKUdkoTx1/Q+IHNokgy+wld4ayvoeIrP3JThh35C8O04bnOe4pOfR2QVHkoJ6365G9sWL gJyXPcMVL69aMTiOrIJiaRNVo06+z2k3xXWM3JlhZ7/bxx72eorJXQRfSd6JrRfj8T0m2xp4d781J pIQu1o6Y2KCQl/6cDFFOlXQNh/sMFo5fsx9jgKa9JiAIdr6K8Kvy/g9/0yYfZE1g+RV85D1vGnvjx QiaaJyBw==; Received: by zero.zsh.org with local id 1pRU3x-0001ZX-1H; Mon, 13 Feb 2023 08:19:49 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lf1-f52.google.com) smtp.remote-ip=209.85.167.52; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-lf1-f52.google.com ([209.85.167.52]:47080) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1pRU39-0000qo-Kp; Mon, 13 Feb 2023 08:19:00 +0000 Received: by mail-lf1-f52.google.com with SMTP id bp15so17706249lfb.13 for ; Mon, 13 Feb 2023 00:18:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Sa6rYSIN2lfP8soq21sLhsXlq7e+6H/O54WbQrfjK98=; b=CELfJYcEtFiOYIueUJl7EyG6gtNm1O3mUW9MOH0nWenjheUPNTtSs+c1dXY83fdhGQ O3Tkgd1ddbVd6JInqVIVmd4O1lTQjc/qpdmmzzTzPFd6xeMz1YH8QcDg0bzlIJJ7KdWk IvyU+mlNHMgQSGcf07jVgkEK1uBQgzTJRCwBNCNcE94FIfdYKM0PITePr0u+ukqnJ1tE r/Os8XFlYtId58xzsq0ibuM59OM3jqj7GWjtQc7KnHPRrZKuZMuPkIq//f8Y7NG/gf+Y xPUfXWKZu201FYDAJxhQQsfzj2sWY1Vwfz7YtCh2dIbl9qaYGY6SJjMkNsM/EdvOIGsX U45A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Sa6rYSIN2lfP8soq21sLhsXlq7e+6H/O54WbQrfjK98=; b=ynRSkxl11URI9glJQqoKJAHZX0jM4q5iDhbP1Iy0uV3hqnAIhQW8huye9xD6om8WFB 9wDucuEdyAUi+mLjWDStaYGVG07o3IIe/e+WRvmevSLEbinB3ajt1ZRsBWHEApoi+o1g iO3uPx6IrF0YhXj6v+Mqfai0dPQ8g0LD2DKMvCmzuJ1AST1Lg9RVQyAstDZqEDLxVCfQ 6lEeMfAEJ2hjCcN4vyd9eE0SxJEwQ930wQqvHWqhDgvrdWs8qWaUW12RmeA17/50+Aex 34syAe5lOUOZdNc1KQ9XhjFeMYzElBm6JNbntxciMTHPq+quP2CC3rhpWmZxM+gLt2Tx BURQ== X-Gm-Message-State: AO0yUKV0TK+4BjdwtNO9tecYNTjKItWjeNnoaen5Cn8yWqFSLBEFtng+ 7oyWzpw82DFb7NZ0H5fmWsRVr2GVRYGZpKxQNtll5H3MtBo= X-Google-Smtp-Source: AK7set9E2e80ve6B3AvBb3KHy9CD8mBUUyh7to9dIB2DtO+QATlsr4Ab+UOxUAkAeAyXwmcYf8NbUlZXrHc/ZguGPes= X-Received: by 2002:a19:ae0a:0:b0:4db:2315:debc with SMTP id f10-20020a19ae0a000000b004db2315debcmr2578153lfc.189.1676276338762; Mon, 13 Feb 2023 00:18:58 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Roman Perepelitsa Date: Mon, 13 Feb 2023 09:18:46 +0100 Message-ID: Subject: Re: Read/write multiple histories from non-interactive shell To: OG Code Poet Cc: zsh-users@zsh.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 28936 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: On Mon, Feb 13, 2023 at 8:36 AM OG Code Poet wrote: > > Let's say there is a non-interactive script with multiple form fields (ea= ch with a different vared), and a user can enter the form multiple times. I= want to preserve individual history for each form field. > > There are two possibilities: > > 1. Keep history internal to the script > I couldn't find an interface for this. Doing ``fc -p`` once in th= e beginning of script does provide an internal history, but it is shared be= tween all vareds (which is not ideal). > 2. Keep history external to the script > Not all ``fc`` commands work. ``fc -R`` does read correctly from = external history files. But ``print -s``, ``fc-W`` and ``fc -A`` do not. Se= ems the only option is to do an echo "$string" >>~/path//form_entry_1.hist = file. But I guess that has disadvantages because it lacks the benefits that= zsh provides in resolving duplicates. > > Is there a way out? Should this also be copied to zsh-workers for feature= request? How about this? #!/usr/bin/env -S zsh -fi histdir=3D~/.formhist mkdir -p -- $histdir || exit function read-field() { emulate -L zsh local var=3D$1 local desc=3D$2 fc -pa $histdir/$var 1000 1000 trap 'exit 130' INT vared -hep "Enter $desc: " -c $var || exit print -rs -- ${(P)var} } while true; do read-field first_name '%F{green}First Name%f' typeset -p first_name unset first_name read-field email '%F{yellow}Email Address%f' typeset -p email unset email done The trap is a workaround for what looks like a bug. Without it, if interrupt vared with Ctrl-C, the history file gets truncated to its first entry. Roman.