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,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 17021 invoked from network); 13 Feb 2023 08:58:37 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 13 Feb 2023 08:58:37 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1676278717; b=GeU+XvAGAU7p/iVItwqiKn0b5RPc47Le5r8vhFNCFe57B6AT18mAEl7Ysv5HsZihzqNFXpLzmK o50KaaZOI6UKcvsz78jbtljnZtlvwMaOhEnVQsoc64jiUYKt+n6jPm9uzC1TEH0s3wRJiU4437 d4/qTGCW+A2A3B0ok8BS2adMi2KUBWtEHTCW+h1hYrYC6yGKuqcUBKFMrUnzgWApI1FF+LUPdi 85ktqCp8VJojsgar6bqdRahuTvOM3wVWuVM68IfUUDXLvz+KuKW5BVEB7oX02zhyMZAE1FR1ZC oxfDxNBfkWHMXcYhUx+e6LkmwK3rgPEPZaPBjX0SwogbpA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-vs1-f46.google.com) smtp.remote-ip=209.85.217.46; 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=1676278717; bh=H3dr2GDTf2AK+5HfVcLRGH0RK0KYY5G2+zOV/ivMHEw=; 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=VwYnQ8BZN8Dp5F9hTq2i9QTnIa2ItfijR4dymdoOBL6LiKUEs+R4ASFS4w8tKDhZXG6/8BmNaE 6oV6ffJkJ4kZVykmTpa1tRjuf7paatnh0nv9+Bh2ffbIk9ujHYQAOY7IDBSMlwVatrOdZZ03tQ ZyLFxr5QyKYmaMlBXdaAzqDqXN/CK6BFJneAngrijZAfg1Z2xIg/d6Xs/mKxhywp6bdI0Nliaa akEQ+G6L/HVKonQOQHA0syJAOmmQT+rvv4r0S5OoaRFa/tDNDPwNRQeqUP3hAxUN4a/3AdBNC6 k5Pej/gWE1k8D9O3WrCpcLNc+pCU4253JLk16bgV0nxWTw==; 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-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=5wYtKV0DkJmhy7lWeyIqLpeRV1nKDnxUSABGJpiNEec=; b=FRVr5DaXmSRnz22N6MGPg4Gvkp XWIuAOWDy8pbNA2x7K5EPGnT4lg58hJEipHjFUIUTlahTvTAzYwoy4TS/EGSTrbF2kQD097+dwLpu vLM7mnoUxGFFlvm6hwIpbun4eak6QM/QyD1ouMvkS8Czj6p8ca6clHswIxTe/zkMYg9g9wFDGiWUw VDFEDbzuEDZ40bzQIUcgx/c4HlHSfWpdN+J0Iaas02bdmCWX+oV4xm9AeD9oGSQ0Qiuw2CieIAdDV gzAcDnLihAtmZ0gBT4MiGUtscJTZ3/yDIWEGbQjUOgRkLTKa9snMRPCtaEwNprbyRNAQQVb+WU5FN ot1CbxmQ==; Received: by zero.zsh.org with local id 1pRUfU-0004fl-NR; Mon, 13 Feb 2023 08:58:36 +0000 Authentication-Results: zsh.org; iprev=pass (mail-vs1-f46.google.com) smtp.remote-ip=209.85.217.46; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-vs1-f46.google.com ([209.85.217.46]:44010) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1pRUej-000409-NT; Mon, 13 Feb 2023 08:57:51 +0000 Received: by mail-vs1-f46.google.com with SMTP id p23so2653517vsq.10 for ; Mon, 13 Feb 2023 00:57:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=5wYtKV0DkJmhy7lWeyIqLpeRV1nKDnxUSABGJpiNEec=; b=YqhM5dV2AjLl2k0Gi/eyFxcl59m5M+34crzlEYPMLAgaRZjsbwSLkHVZK4BbzDLcWx YwRduKK9zbwngxf9RDv97FtGTBnLOHudLCJ/VpNZTN4mqPBnc/rS+XIERqmDJ1hHxI+s T3NjLNUzwIdGGVS/PUsKKXDJb+OXR7iSl8YGKIqI9cJR/ofrsS2eod5VHCySOi4muLu6 e+wAWfPlvC9s8lU9JMetPSi721erxSoNSUZNsWNkBm7yNJrLVQ5/eknkxq5u6qMd5eTt aJ7dNhSt8dMySE3o0YIOTOsEMhBGEA0v1cRfKRJJqmftPpDUjTul3DjZBoIB5QZ6KLKs hHLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=5wYtKV0DkJmhy7lWeyIqLpeRV1nKDnxUSABGJpiNEec=; b=7GdVVQgRq9E0SyzYqdNSzwLe3Mauo0w6LveKlAecRmWo5ZDXInB6l5SAzfjEOtOHIE LydOEmEMWe7pQvJQxiFkyuQNUDc5a4d6ENhzrnHJZPvkezN85pZ3t4VD/B9Dcgst5a0X rTHCUyOVkdYe4xFXf/CfDy1SeHXaXBrLmTZZer+/RI/+ykGERO4W/pQhbAG58NH7fDkA RlevEsX11jXMCIwdOrL119Lu6l3GvkyijRFChCTtBAvTQarcOrvduM/JvOUMpjksN+zz j1CbmlgnUdfl3N02deu6abj/nb1hxew5vDGpUdTacCRtKuj1ml2DQCVUm8y2g1I+Dxct vSmg== X-Gm-Message-State: AO0yUKV/2nDZ4n9Apz3KxLWrJ0vWogEXR9zZbynFnX4vmlJfDKt5D0G1 zGwIZ4gtnUW9sR5n1cPlxjUE/e8D2AZgjnFyn34= X-Google-Smtp-Source: AK7set8lDB7NBHUUyMRNzqwFkH0KWTKcWo4kjc24t0zB6nT1F238oh6NPbmQ6L1NMsUsy6XNsZcllWNHjdOix8Z7aDY= X-Received: by 2002:a05:6102:3004:b0:412:3897:ea69 with SMTP id s4-20020a056102300400b004123897ea69mr107456vsa.42.1676278668685; Mon, 13 Feb 2023 00:57:48 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: OG Code Poet Date: Mon, 13 Feb 2023 00:57:37 -0800 Message-ID: Subject: Re: Read/write multiple histories from non-interactive shell To: Roman Perepelitsa Cc: zsh-users@zsh.org Content-Type: multipart/alternative; boundary="00000000000097755405f4910a38" X-Seq: 28938 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: --00000000000097755405f4910a38 Content-Type: text/plain; charset="UTF-8" I tried pretty much same code but without "zsh -i", that's why the subject says "non-interactive". My larger script misbehaves and exits with 0 before it could complete if I replace #!/usr/bin/env zsh with #!/usr/bin/env -S zsh -fi or #!/usr/bin/env -S zsh -i. Is there a restriction on starting any existing functional zsh program with -fi? Put another way, are all non-interactive shell scripts guaranteed to function when shebang is changed to #!/usr/bin/env -S zsh -fi?? On Mon, Feb 13, 2023 at 12:18 AM Roman Perepelitsa < roman.perepelitsa@gmail.com> wrote: > 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 > (each 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 > the beginning of script does provide an internal history, but it is shared > between 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. > Seems 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=~/.formhist > mkdir -p -- $histdir || exit > > function read-field() { > emulate -L zsh > local var=$1 > local desc=$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. > --00000000000097755405f4910a38 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I tried pretty much same code but without "zsh -i&quo= t;, that's why the subject says=C2=A0"non-interactive". My la= rger script misbehaves and exits with 0 before it could complete if I repla= ce=C2=A0#!/usr/bin/env zsh with=C2=A0#!/usr/bin/env -S zsh -fi or=C2=A0#!/u= sr/bin/env -S zsh -i. Is there a restriction on starting any existing funct= ional zsh program with -fi? Put another way, are all non-interactive shell = scripts guaranteed to function when shebang is changed to=C2=A0#!/usr/bin/e= nv -S zsh -fi??


On Mon, Feb 13, 2023 at 12:18 AM Roman Perepe= litsa <roman.perepelitsa@= gmail.com> wrote:
On Mon, Feb 13, 2023 a= t 8:36 AM OG Code Poet <ogcodepoet@gmail.com> wrote:
>
> Let's say there is a non-interactive script with multiple form fie= lds (each with a different vared), and a user can enter the form multiple t= imes. I want to preserve individual history for each form field.
>
> There are two possibilities:
>
> 1. Keep history internal to the script
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0I couldn't find an interface for = this. Doing ``fc -p`` once in the beginning of script does provide an inter= nal history, but it is shared between all vareds (which is not ideal).
> 2. Keep history external to the script
>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0Not all ``fc`` commands work. ``fc -R= `` does read correctly from external history files. But ``print -s``, ``fc-= W`` and ``fc -A`` do not. Seems the only option is to do an echo "$str= ing" >>~/path//form_entry_1.hist file. But I guess that has disa= dvantages because it lacks the benefits that zsh provides in resolving dupl= icates.
>
> Is there a way out? Should this also be copied to zsh-workers for feat= ure request?

How about this?

=C2=A0 =C2=A0 #!/usr/bin/env -S zsh -fi

=C2=A0 =C2=A0 histdir=3D~/.formhist
=C2=A0 =C2=A0 mkdir -p -- $histdir || exit

=C2=A0 =C2=A0 function read-field() {
=C2=A0 =C2=A0 =C2=A0 emulate -L zsh
=C2=A0 =C2=A0 =C2=A0 local var=3D$1
=C2=A0 =C2=A0 =C2=A0 local desc=3D$2
=C2=A0 =C2=A0 =C2=A0 fc -pa $histdir/$var 1000 1000
=C2=A0 =C2=A0 =C2=A0 trap 'exit 130' INT
=C2=A0 =C2=A0 =C2=A0 vared -hep "Enter $desc: " -c $var || exit =C2=A0 =C2=A0 =C2=A0 print -rs -- ${(P)var}
=C2=A0 =C2=A0 }

=C2=A0 =C2=A0 while true; do
=C2=A0 =C2=A0 =C2=A0 read-field first_name '%F{green}First Name%f'<= br> =C2=A0 =C2=A0 =C2=A0 typeset -p first_name
=C2=A0 =C2=A0 =C2=A0 unset first_name

=C2=A0 =C2=A0 =C2=A0 read-field email '%F{yellow}Email Address%f' =C2=A0 =C2=A0 =C2=A0 typeset -p email
=C2=A0 =C2=A0 =C2=A0 unset email
=C2=A0 =C2=A0 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.
--00000000000097755405f4910a38--