Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: save a command in history from within the widget



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