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

Re: Is there any possible way to automatically escape characters when executing an alias in zsh?



On Sat, 2021-09-11 at 16:45 -0400, Steve Dondley wrote:
> On 2021-09-11 03:28 PM, Peter Stephenson wrote:
> > On Sat, 2021-09-11 at 20:16 +0100, Peter Stephenson wrote:
> > > accept-with-quote() {
> > >   if [[ $BUFFER = 'tasn '* && $BUFFER != *\\* ]]; then
> > >       BUFFER=${BUFFER//\'/\\\'}
> > >   fi
> > > }
> > > zle -N zle-line-finish accept-quote
> 
> Very cool. It works! No idea what the zle command does but I'll google 
> it. Thanks!
> 
> I have a number of aliases that begin with "ta" and "tm" that could 
> benefit from this trick. I imagine I could turn the 'tasn '* bit into a 
> regex test to check for a match.

"man zshzle" will tell you about special widgets.  Basically, they're
just user defined commands that instead of being called by a keystroke
are called at particular points during editing.

The test is just an ordinary zsh pattern, as used for globbing / file
matching, so it's easy to extend...

if [[ $BUFFER = (tasn|taxx|tmxx)' '* && $BUFFER != *\\* ]]; then
  ...

pws





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