zsh-users
 help / color / mirror / code / Atom feed
From: Ahmad Ismail <ismail783@gmail.com>
To: Daniel Shahaf <d.s@daniel.shahaf.name>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: save a command in history from within the widget
Date: Mon, 26 Oct 2020 03:13:32 +0600	[thread overview]
Message-ID: <CAHAhJwK_LFjnZJx_-cc=n9UbkwZ6KD6br2V3M7WtvvHHvOeezg@mail.gmail.com> (raw)
In-Reply-To: <20201025202419.528548e8@tarpaulin.shahaf.local2>

[-- Attachment #1: Type: text/plain, Size: 3264 bytes --]

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 = "!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 =~ ^"g d untrack-all" ]]
then
*zle save-to-history $BUFFER*
BUFFER="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 =~ '^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 <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 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
>

[-- Attachment #2: Type: text/html, Size: 6370 bytes --]

  reply	other threads:[~2020-10-25 21:14 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-24 19:00 Ahmad Ismail
2020-10-25 20:24 ` Daniel Shahaf
2020-10-25 21:13   ` Ahmad Ismail [this message]
2020-10-26 22:04     ` Daniel Shahaf
2020-10-27 19:01       ` Ahmad Ismail
2020-10-26  7:11   ` Roman Perepelitsa
2020-10-26 11:15     ` Ahmad Ismail
2020-10-26 14:19       ` Ahmad Ismail
2020-10-29 11:07 ` Lewis Butler
2020-10-29 23:54   ` Ahmad Ismail

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHAhJwK_LFjnZJx_-cc=n9UbkwZ6KD6br2V3M7WtvvHHvOeezg@mail.gmail.com' \
    --to=ismail783@gmail.com \
    --cc=d.s@daniel.shahaf.name \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).