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

Re: Macro's



fREW wrote:
> I was reading the book From Bash to Z Shell and it mentioned that
> macros are possible with Bash but not zsh, so I did a search on Google
> and found a patch for readline style macros that had been submitted
> just shy of TEN YEARS ago.  Is there any possibility that such a
> feature still may be added?  Or will it have to be either a hack or
> too much reworking to happen?

It's the sort of thing that can be written as a custom editor command
(see chapter 14).

As a very quick attempt to make something work, try the following:
  start-kbd-macro() {
    local macro
    while
      read -k 1
    [[ $REPLY != \) ]] || (( ##$macro[-1] != 24 )); do
      macro+="$REPLY"
    done
    bindkey -s '^Xe' "$macro[1,-2]"
  }
  zle -N start-kbd-macro
  bindkey '^X)' start-kbd-macro

This can be improved in many ways. It doesn't pass the keys pressed on
to the line editor so they don't work as you record the macro. It
doesn't display a message to tell you that macro recording is in
progress. It has also hard coded the key for ending macro recording.

Oliver



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