zsh-users
 help / color / mirror / code / Atom feed
From: Ahmad Ismail <ismail783@gmail.com>
To: Lewis Butler <lbutler@covisp.net>
Cc: Zsh Users <zsh-users@zsh.org>
Subject: Re: save a command in history from within the widget
Date: Fri, 30 Oct 2020 05:54:13 +0600	[thread overview]
Message-ID: <CAHAhJwJDSuLZxXUgsC7fhScuordi4+F7J-_ngOcJ5kozxvRzdw@mail.gmail.com> (raw)
In-Reply-To: <0E85AE23-69A6-41EB-AC00-8EEF5587DF03@covisp.net>

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

Hi Lewis Butler,

The problem I was trying to solve is given in

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

let me explain the code you referred to. accept-line widget is invoked
after we press enter in the command line. I replace that with
_check-if-dotfile-command using the following line

zle -N accept-line _check-if-dotfile-command

The code took the command (which is in the  $BUFFER) and replaced it with
another string and then ran accept-line widget. For example any line
starting with `g d stash-and-reset` was replaced with `git d stash && git d
reset --hard HEAD`.


*Thanks and Best Regards,Ahmad Ismail*


On Thu, Oct 29, 2020 at 5:07 PM Lewis Butler <lbutler@covisp.net> wrote:

> On 24 Oct 2020, at 13:00, Ahmad Ismail <ismail783@gmail.com> wrote:
> > I am currently working on a widget. It is used so that I can use my git
> alias also for my dotfiles.
>
> This is, to me, very advanced zsh and while reading through it I am still
> not exactly sure what it does or what the purpose is.
>
> > The widget is given bellow:
> >
> > function _check-if-dotfile-command {
> >
> >     if  [[ $BUFFER =~ ^"g d untrack-all" ]]
> >     then
> >       zle .kill-whole-line
> >       BUFFER="g d rm --cached -r ~"
> >       zle .accept-line
> >     elif [[ $BUFFER =~ ^"g d add-and-commit" ]]
> >     then
> >       BUFFERz=$(echo $BUFFER | cut -d '"' -f2)
> >       zle .kill-whole-line
> >       BUFFER="git d add ~ && g d commit -am \"${BUFFERz}\""
> >       zle .accept-line
> >     elif [[ $BUFFER =~ ^"g d sb" ]]
> >     then
> >       zle .kill-whole-line
> >       BUFFER="git d branch | rofi -dmenu | xargs git checkout"
> >       zle .accept-line
> >     elif [[ $BUFFER =~ ^"g d stash-and-reset" ]]
> >     then
> >       zle .kill-whole-line
> >       BUFFER="git d stash && git d reset --hard HEAD"
> >       zle .accept-line
> >     elif [[ $BUFFER =~ ^"g d last" ]]
> >     then
> >       zle .kill-whole-line
> >       BUFFER="git d --no-pager log -1 --oneline"
> >       zle .accept-line
> >     else
> >         zle .accept-line
> >     fi
> > }
> >
> > zle -N accept-line _check-if-dotfile-command
>
> I currently have a directory named ~/.shell which is a git repo for all
> the various . Files in my home folder (via hard links). What is the widget
> intended to do and how is it triggered?
>
> (I realize you've moved away from this widget, but what were you trying
> for).
>
> --
> ɹןʇnqן
> <mailto:lbutler@covisp.net>
> tel:+1.303.219.0564
>
>
>
>
>

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

      reply	other threads:[~2020-10-29 23:54 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
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 [this message]

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=CAHAhJwJDSuLZxXUgsC7fhScuordi4+F7J-_ngOcJ5kozxvRzdw@mail.gmail.com \
    --to=ismail783@gmail.com \
    --cc=lbutler@covisp.net \
    --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).