Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: save a command in history from within the widget
- X-seq: zsh-users 26129
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: Ahmad Ismail <ismail783@xxxxxxxxx>
- Subject: Re: save a command in history from within the widget
- Date: Sun, 25 Oct 2020 20:24:19 +0000
- Archived-at: <https://zsh.org/users/26129>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-users/2020-10/20201025202419.528548e8%40tarpaulin.shahaf.local2>
- Authentication-results: zsh.org; iprev=pass (out4-smtp.messagingengine.com) smtp.remote-ip=66.111.4.28; dkim=pass header.d=daniel.shahaf.name header.s=fm1 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm1 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none
- Cc: Zsh Users <zsh-users@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=date:from:to:cc:subject:message-id :in-reply-to:references:mime-version:content-type :content-transfer-encoding; s=fm1; bh=shg3hiGZR0kNckBCGwfAZPPA+n JNxVMekfsMm9EvbLw=; b=xC1sV8kXwD+RGZ0rZR9X9kUUunfRv4oQLAgH3CZaXv AIndQBHY0EnDIbvy1XglX4DfaBQyoN3esN3NYmo5yGKIGkfRqRaUVkCDm654XPOj 3n+ddyaxNdB2tpc9JTDzXMwRih3oPcqpPvsAA9JLX95B9g2w8hD4ub7io3ix0M6X Q0n45KvB5sTHz7l2pIxCcniHB8FY2tc4+3x/otKE73P7BSTBdu2M8Zc3gi16Bnbs ESBBOea8C+hB9YSp7CeFSVhr9jzSO5CvFQaGytuPIF+gPtyBHIH7SyznzKqvWuY1 /pqUdvVCN3wBl18HRddnVnS0gYQ8iRs1g09McINgFRqA==
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; bh=shg3hiGZR0kNckBCGwfAZPPA+nJNxVMekfsMm9Evb Lw=; b=IbmWgJ/WttQSJXyQ0xIJ/DuJcZRZJW5m77mVHouRGe03FwvaV9wElHOdT IIXuwt9rT05OxbNcBo3MprXvunbc3cf5lrfsWuL8J3BX27yXzdKM57ieOToevHwE WnDKIVV3dScJi6bZamrn4yN3YvjwKLmaYbbDlobud4ByYsNmtK3LNNUVgCpPN0C3 szg3wfz2RCdE0vIt6tidAGbJu7ZB4qxkk+QRDNx6r7cOPL+2OYnxXXrPNLZNyiwM KsD/p7MFEbGSmX6diTKi27F+LJGaX6zI6PIWyLeKtVo0uIejnz8fqCLNrGsZlOqP PyT81cnqEYqeWU2ATsWXiU43Dg4qg==
- In-reply-to: <CAHAhJw+EVFVoXT7Wp_dTMwVy4__Za+umR3cgmmY1Crr5y5+6Qg@mail.gmail.com>
- List-archive: <http://www.zsh.org/sympa/arc/zsh-users>
- List-help: <mailto:sympa@zsh.org?subject=help>
- List-id: <zsh-users.zsh.org>
- List-owner: <mailto:zsh-users-request@zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-subscribe: <mailto:sympa@zsh.org?subject=subscribe%20zsh-users>
- List-unsubscribe: <mailto:sympa@zsh.org?subject=unsubscribe%20zsh-users>
- References: <CAHAhJw+EVFVoXT7Wp_dTMwVy4__Za+umR3cgmmY1Crr5y5+6Qg@mail.gmail.com>
- Sender: zsh-users-request@xxxxxxx
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:
⋮
> 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 «g» alias in your dotfiles, but then you gave an example from
interactive use, and in any case dotfiles don't run widgets.
In any case, I'd scratch the approach of checking [[ $BUFFER =~ '^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 «g»
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author