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

Re: save a command in history from within the widget



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@xxxxxxxxxx> wrote:
On 24 Oct 2020, at 13:00, Ahmad Ismail <ismail783@xxxxxxxxx> 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@xxxxxxxxxx>
tel:+1.303.219.0564






Messages sorted by: Reverse Date, Date, Thread, Author