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

Re: history expansion



On 2/20/20, Pier Paolo Grassi <pierpaolog@xxxxxxxxx> wrote:
> something like an alias that could allow me to reuse history expandable
> expressions, such as !!, !:1, ^cdcd^cddcd and so on

If you make an alias like normal, but instead of pressing enter, press
^Xa (_expand_alias), it should do what you want. This could then be
extended with a custom widget bound to accept-line that checks if the
current input is one of your special history-aliases and expand it for
you before accepting the line, etc.
skeleton example of the latter,
zle -N accept-line accept-line-history-alias
accept-line-history-alias() {
  if [[ $BUFFER = histalias-* ]]; then
    zle _expand_alias
  fi
  zle .$WIDGET
}
if you go this route, you could also use a custom lookup assoc array
instead of using aliases.

-- 
Mikael Magnusson



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