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,T_KAM_HTML_FONT_INVALID,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 5773 invoked from network); 25 Oct 2020 21:14:20 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 25 Oct 2020 21:14:20 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1603660460; b=uJMQncbHj5XrK32cDJ+gHl4K2UQs6VBi6QfEdZw7dXi/+gaGaICsIF8lpFfX1PIcNhZls+9enr +HPpqlD7x5jGRHc34SARAfPZNUKzNYAON5xCA1d1k4ze8e1Y2nr5n6lzVkR4aducraV3pLMN8S Jr10OU1zvxkgJHGpbaJH1zqvhkS9Ed+8iHrplZ9+Io1UxJuWuIL2P7e+ACsUG9B0BuySz9GHl4 u740obsQTTC/PUJ3CgB/vH09bA1J5OXlZXVt1/9XfU94TzYuTK5nHkfnKTJn4QhbcXgrv9zUxe QpPESx5O/tjB6ArMXIL6ShEzKK63k9onzV9KMNY8TaAbSQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-oi1-f177.google.com) smtp.remote-ip=209.85.167.177; dkim=pass header.d=gmail.com header.s=20161025 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-20200801; t=1603660460; bh=CPi9PKa6HYfMdRr3agJhKWejM/Tmd95+Mw3efYkXWvo=; 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=RZU9KBUEY6pr2lHABxb/l+RAA3wPDBIwRLCmld7Te1a4iDckPrq0+OP8S6qphIZeMy4fJqDxQA at0XvcoxudmL/qdC3nQwYGqQ5MbrqDvKjYu9RO+VjOTDS2VMNqzi+Q/CxFvwnhfc29WnOHpYIN URuAqFZloFHkHDABl3f81W537yVYsSuQuJCii7N07vHWSQqLg8TP7xvlH+TTjh4ov18OwjoO/G p078c/AtmfeH6GSjg0GkjQjMM/nsJlyqSEZZ617o/NDhiTysSavOovt2GB6OeHBRn6n06sE/+O gqJTWjVHkrv5HHu8FIzMWKp7Cm+IItcMXReeHAAlP5IoOQ==; 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=GnR66Ge5dDKx4jq3dn7tNTOtx8Wi+j5VHBU2M/6R450=; b=ZI2o8lQ1mTUDP2NRUawdsVcXCx cwLKihKfUE3IPltNJSIb1qC1Gnfz8jkr6Py037srej6huV2wcBBMz5BeIPfB2F8GoNkRfEg1TTSKy 2SDiOONWpPRrM32KHMuwW2rr6D4CwHJb5+2Xuu1vzEz01bPPpXHIu00EdCI1JBc4+QK7X3R5Ve0JU 8trslqcS6E4WGeJoBg51KvR7B6nuqy/k3+gEJVn6MqH62kXIJhDAcPWEfg/FPErkPwlJGyBghs4kS VdQsZBg31tckdoVXWIyXMWEeIpIyT4yMYhIC6Ee2LH7nc95nGRMk2+061z/D8nLfxJ0pxgV93x+cF iG4r/rFg==; Received: from authenticated user by zero.zsh.org with local id 1kWnLE-000CvX-2L; Sun, 25 Oct 2020 21:14:16 +0000 Authentication-Results: zsh.org; iprev=pass (mail-oi1-f177.google.com) smtp.remote-ip=209.85.167.177; dkim=pass header.d=gmail.com header.s=20161025 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-oi1-f177.google.com ([209.85.167.177]:46227) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1kWnKi-000CZC-RS; Sun, 25 Oct 2020 21:13:46 +0000 Received: by mail-oi1-f177.google.com with SMTP id x1so762332oic.13 for ; Sun, 25 Oct 2020 14:13:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=GnR66Ge5dDKx4jq3dn7tNTOtx8Wi+j5VHBU2M/6R450=; b=W2gwmhnhSP8a/l+xAqkfJLzrrSaacD/OwMTxShKdZcrwvjzZJiHCAVzIOLT9Fz5/j2 pKkKgr25YH5H3+J+pyVcG75VgfuplGmwnVNgMYXuSpYFf4R+rDBNdn+iXdHJ2GN+G70C eX+4OlAV08+AeJWSNkRt0FydDQwv2I+BVqrVSivXWbRNiXamwsMSzX3WAGTwC1Bep0vR H65rUzRia5mWSZM0dH6mgfAzO6imNoaw2lIKxAqY4J4tXnychsIMW8txK0FmLOVR2IiY +LcpJ7/xy6QgFue68+IMRkB6sQwxHYSFEgoJdfi1+bbH3i2ZoabtFvnFiPrLqc93UjiY R0Yg== 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=GnR66Ge5dDKx4jq3dn7tNTOtx8Wi+j5VHBU2M/6R450=; b=ECCqZhjsZwzqD4WC9HtZUbE9Nxqv487fHKLZgUirjsj0agWpEUzbehgoNnSWK6Bbhl q/Q4XYnYmXZn4xjvm8v6AcnQG/d/iCWeKhKzs7RXcuF/8V0r5oVsXWr1WcJtFgMOhEYX 1h13/9JfQ8PpjFxBfPbe/ZMSUiatS88DYq8M0oYc0SlMkPz2rqrDb/9sA+MiazSgOTvR NrzGqoqKl+ztFhr1jf1XCR1yptLw4kP0nxZ0yN7AzXlcfi4fgGgiu9npbVu4QlayHOzl lp2Z0ejpCk6sOPBaieaKfAdv8Et6P2NtKAJOKs65aeHwyVnExgeHhSS9IRRbMFXV4h7c S15A== X-Gm-Message-State: AOAM532z+PINVNANFPt3oetx+ZmNvKYytRhdex1bkzRVjYHQVQ10mHK9 8pfRV5za41S2I4eW4rlI3DDhLu7M3KTGaQ4VxaQ= X-Google-Smtp-Source: ABdhPJy3X/ew3pz8UOPq75lH/6kb+Pss0P4IBowfHuSwGDJ5CSP/1KLqysZWXpy3o2bHOeTLiqwgW0wnXk/st2QJlVk= X-Received: by 2002:a05:6808:aa1:: with SMTP id r1mr8564516oij.153.1603660423686; Sun, 25 Oct 2020 14:13:43 -0700 (PDT) MIME-Version: 1.0 References: <20201025202419.528548e8@tarpaulin.shahaf.local2> In-Reply-To: <20201025202419.528548e8@tarpaulin.shahaf.local2> From: Ahmad Ismail Date: Mon, 26 Oct 2020 03:13:32 +0600 Message-ID: Subject: Re: save a command in history from within the widget To: Daniel Shahaf Cc: Zsh Users Content-Type: multipart/alternative; boundary="000000000000e4ef0705b2854903" X-Seq: 26130 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: Archived-At: --000000000000e4ef0705b2854903 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Daniel Shahaf, Thank you very much for responding. To get some context to my use case you can check: https://www.reddit.com/r/git/comments/jdl11c/can_not_use_some_of_my_aliases= _with_bare_repo/ https://stackoverflow.com/questions/64416625/can-not-use-some-of-my-aliases= -with-bare-repo Long story short, as far I know, there is no easy way to use some of my aliases with bare repo. There are some solutions like special git alias like: example1 =3D "!f() { .....; }; f" However, I am feeling much comfortable with this approach. Here, I am trying to change my command on the fly by running it before accept-line. The widget is working perfectly for me except, it is not saving the original buffer in the history. I need a command or widget like *save-to-history *so that I can use it the following way: if [[ $BUFFER =3D~ ^"g d untrack-all" ]] then *zle save-to-history $BUFFER* BUFFER=3D"g d rm --cached -r ~" zle .accept-line .... That way I can save the value of the $BUFFER in the .zsh_history file in proper format. And yes you are right when you said: I'd scratch the approach of checking [[ $BUFFER =3D~ '^g d foo' ]], > because it'll break as soon as you want to interactively use complex > commands (e.g., sublists, lists, conditions, loops). > But, this script is only for my personal use, so I will continue tweaking it as per my requirement. Being said that, I actually do not know how to check PREBUFFER before checking BUFFER. I will be glad if you can give me some code to fix this issue. *Thanks and Best Regards,Ahmad Ismail* On Mon, Oct 26, 2020 at 2:24 AM Daniel Shahaf wrote: > Ahmad Ismail wrote on Sun, 25 Oct 2020 01:00 +0600: > > I am currently working on a widget. It is used so that I can use my git > > alias also for my dotfiles. > > > > The widget is given bellow: > =E2=8B=AE > > Now, the problem is, the commands I am invoking are not being saved in > the > > history file. > > For example, if I use: > > > > % g d add-and-commit "Few Modifications" > > > > it saves: > > > > : 1603565685:0;git d add ~ && g d commit -am "Few Modifications" > > > > I know the command below is the command I actually ran. But I want to > save > > the command I used as well. Is there any way I can save a command in > > history from within the widget? > > I don't understand your use-case. You stated your purpose is to use > your =C2=ABg=C2=BB alias in your dotfiles, but then you gave an example f= rom > interactive use, and in any case dotfiles don't run widgets. > > In any case, I'd scratch the approach of checking [[ $BUFFER =3D~ '^g d f= oo' > ]], > because it'll break as soon as you want to interactively use complex > commands (e.g., sublists, lists, conditions, loops). > > I don't understand why you can't drop a script literally called =C2=ABg= =C2=BB > into a directory in $path and implement in it whatever logic you want. > (Or possibly a function, depending on your use-case.) > > As to your widget code, you don't need kill-whole-line if you set > BUFFER explicitly. Also, you check BUFFER without first checking > PREBUFFER, which is subtly wrong because $PREBUFFER may end with a line > continuation. > > Cheers, > > Daniel > --000000000000e4ef0705b2854903 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi Daniel Shahaf,

Thank you = very much for responding. To get some context to my use case you can check:=


Long story short, as far I know, there is no easy way to use some = of my aliases with bare repo. There are some solutions like special git alias like:

example1 =3D "!f() { = .....; }; f"

However, I am feeling much comfortable with this approach. Here, I am= trying to change my command on the fly by running it before accept-line. T= he widget is working perfectly for me except, it is not saving the original= buffer in the history.

I need a command or widget= like save-to-history so that I can use it the following way:

if [[ $BUFFER =3D~ ^"g d untrack-all"= ]]
then
zle save-to-history $BUFFER
BUFFER=3D"g d rm --cached -r ~"
zle .accept-line
....

That wa= y I can save the value of the $BUFFER in the .zsh_history file in proper format.

And yes you are right when you said:

I'd scratch the ap= proach of checking [[ $BUFFER =3D~ '^g d foo' ]],
because it'll break as soon as you want to interactively use complex commands (e.g., sublists, lists, conditions, loops).
=

But, this script is only for my personal use, so I will= continue tweaking it as per my requirement.

Being= said that, I actually do not know how to check PREBUFFER before checking B= UFFER. I will be glad if you can give me some code to fix this issue.
=

Thanks a= nd Best Regards,

Ahmad Ismail



On = Mon, Oct 26, 2020 at 2:24 AM Daniel Shahaf <d.s@daniel.shahaf.name> wrote:
Ahmad Ismail wrote on Sun, 25 Oct 2020 = 01:00 +0600:
> I am currently working on a widget. It is used so that I can use my gi= t
> alias also for my dotfiles.
>
> The widget is given bellow:
=E2=8B=AE
> Now, the problem is, the commands I am invoking are not being saved in= the
> history file.
> For example, if I use:
>
> % g d add-and-commit "Few Modifications"
>
> it saves:
>
> : 1603565685:0;git d add ~ && g d commit -am "Few Modific= ations"
>
> I know the command below is the command I actually ran. But I want to = save
> the command I used as well. Is there any way I can save a command in > history from within the widget?

I don't understand your use-case.=C2=A0 You stated your purpose is to u= se
your =C2=ABg=C2=BB alias in your dotfiles, but then you gave an example fro= m
interactive use, and in any case dotfiles don't run widgets.

In any case, I'd scratch the approach of checking [[ $BUFFER =3D~ '= ^g d foo' ]],
because it'll break as soon as you want to interactively use complex commands (e.g., sublists, lists, conditions, loops).

I don't understand why you can't drop a script literally called =C2= =ABg=C2=BB
into a directory in $path and implement in it whatever logic you want.
(Or possibly a function, depending on your use-case.)

As to your widget code, you don't need kill-whole-line if you set
BUFFER explicitly.=C2=A0 Also, you check BUFFER without first checking
PREBUFFER, which is subtly wrong because $PREBUFFER may end with a line
continuation.

Cheers,

Daniel
--000000000000e4ef0705b2854903--