zsh-users
 help / color / mirror / code / Atom feed
* Is there any possible way to automatically escape characters when executing an alias in zsh?
@ 2021-09-11 18:41 Steve Dondley
  2021-09-11 19:00 ` zzapper
  2021-09-11 19:16 ` Peter Stephenson
  0 siblings, 2 replies; 16+ messages in thread
From: Steve Dondley @ 2021-09-11 18:41 UTC (permalink / raw)
  To: Zsh users

I have many aliases set up for taskwarrior in zsh:

alias tasn="task +sn add"`

On the command line, I'll type in:

tasn some task description here

Which works unless I put in single quote or some other character:

tasn call Tom's friend

This will thrown an error unless I escape the apostrophe.

I don't want to turn these into functions because then I lose the 
autocomplete capabilities. I'm wondering if there might be some neat 
trick that will allow me to automatically escape apostrophes (and other 
problematic characters) in the task description.

Thanks.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Is there any possible way to automatically escape characters when executing an alias in zsh?
  2021-09-11 18:41 Is there any possible way to automatically escape characters when executing an alias in zsh? Steve Dondley
@ 2021-09-11 19:00 ` zzapper
  2021-09-11 19:16 ` Peter Stephenson
  1 sibling, 0 replies; 16+ messages in thread
From: zzapper @ 2021-09-11 19:00 UTC (permalink / raw)
  To: zsh-users


On 11/09/2021 19:41, Steve Dondley wrote:
> I have many aliases set up for taskwarrior in zsh:
>
> alias tasn="task +sn add"`
>
> On the command line, I'll type in:
>
> tasn some task description here
>
> Which works unless I put in single quote or some other character:
>
> tasn call Tom's friend

I tried a heredoc

alias mucky=<<EOD

echo tom's friend

EOD


But it doesn't work :(



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Is there any possible way to automatically escape characters when executing an alias in zsh?
  2021-09-11 18:41 Is there any possible way to automatically escape characters when executing an alias in zsh? Steve Dondley
  2021-09-11 19:00 ` zzapper
@ 2021-09-11 19:16 ` Peter Stephenson
  2021-09-11 19:28   ` Peter Stephenson
  1 sibling, 1 reply; 16+ messages in thread
From: Peter Stephenson @ 2021-09-11 19:16 UTC (permalink / raw)
  To: zsh-users

On Sat, 2021-09-11 at 14:41 -0400, Steve Dondley wrote:
> I have many aliases set up for taskwarrior in zsh:
> 
> alias tasn="task +sn add"`
> 
> On the command line, I'll type in:
> 
> tasn some task description here
> 
> Which works unless I put in single quote or some other character:
> 
> tasn call Tom's friend
> 
> This will thrown an error unless I escape the apostrophe.
> 
> I don't want to turn these into functions because then I lose the 
> autocomplete capabilities. I'm wondering if there might be some neat 
> trick that will allow me to automatically escape apostrophes (and other 
> problematic characters) in the task description.

Like this.


accept-with-quote() {
  if [[ $BUFFER = 'tasn '* && $BUFFER != *\\* ]]; then
      BUFFER=${BUFFER//\'/\\\'}
  fi
}
zle -N zle-line-finish accept-quote


Note that the line as updated is what goes into the history --- that's
why I've looked for the backslash and not update the line further if
there's one there.

pws



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Is there any possible way to automatically escape characters when executing an alias in zsh?
  2021-09-11 19:16 ` Peter Stephenson
@ 2021-09-11 19:28   ` Peter Stephenson
  2021-09-11 20:45     ` Steve Dondley
  0 siblings, 1 reply; 16+ messages in thread
From: Peter Stephenson @ 2021-09-11 19:28 UTC (permalink / raw)
  To: zsh-users

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

obviously, that should be 'accept-with-quote' again, not 'accept-quote'.

pws




^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Is there any possible way to automatically escape characters when executing an alias in zsh?
  2021-09-11 19:28   ` Peter Stephenson
@ 2021-09-11 20:45     ` Steve Dondley
  2021-09-11 20:53       ` Peter Stephenson
  0 siblings, 1 reply; 16+ messages in thread
From: Steve Dondley @ 2021-09-11 20:45 UTC (permalink / raw)
  To: zsh-users

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.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Is there any possible way to automatically escape characters when executing an alias in zsh?
  2021-09-11 20:45     ` Steve Dondley
@ 2021-09-11 20:53       ` Peter Stephenson
  2021-09-11 21:01         ` Steve Dondley
  0 siblings, 1 reply; 16+ messages in thread
From: Peter Stephenson @ 2021-09-11 20:53 UTC (permalink / raw)
  To: zsh-users

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



^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Is there any possible way to automatically escape characters when executing an alias in zsh?
  2021-09-11 20:53       ` Peter Stephenson
@ 2021-09-11 21:01         ` Steve Dondley
  2021-09-11 22:39           ` Lawrence Velázquez
  0 siblings, 1 reply; 16+ messages in thread
From: Steve Dondley @ 2021-09-11 21:01 UTC (permalink / raw)
  To: zsh-users


> "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

Nice. Yeah, this annoyance has been bugging me for years. I'll share 
this out to the TW community, I'm sure others will love this, too.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Is there any possible way to automatically escape characters when executing an alias in zsh?
  2021-09-11 21:01         ` Steve Dondley
@ 2021-09-11 22:39           ` Lawrence Velázquez
  2021-09-11 23:15             ` Steve Dondley
  2021-09-11 23:17             ` Bart Schaefer
  0 siblings, 2 replies; 16+ messages in thread
From: Lawrence Velázquez @ 2021-09-11 22:39 UTC (permalink / raw)
  To: Steve Dondley; +Cc: zsh-users

On Sat, Sep 11, 2021, at 5:01 PM, Steve Dondley wrote:
> 
> > "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
> 
> Nice. Yeah, this annoyance has been bugging me for years. I'll share 
> this out to the TW community, I'm sure others will love this, too.

This is fun and all, but it's not clear to me why this is desirable
over, say:

    % tasn "call Tom's friend"

-- 
vq


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Is there any possible way to automatically escape characters when executing an alias in zsh?
  2021-09-11 22:39           ` Lawrence Velázquez
@ 2021-09-11 23:15             ` Steve Dondley
  2021-09-12  0:23               ` Bart Schaefer
  2021-09-11 23:17             ` Bart Schaefer
  1 sibling, 1 reply; 16+ messages in thread
From: Steve Dondley @ 2021-09-11 23:15 UTC (permalink / raw)
  To: Lawrence Velázquez; +Cc: zsh-users

On 2021-09-11 06:39 PM, Lawrence Velázquez wrote:
> On Sat, Sep 11, 2021, at 5:01 PM, Steve Dondley wrote:
>> 
>> > "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
>> 
>> Nice. Yeah, this annoyance has been bugging me for years. I'll share
>> this out to the TW community, I'm sure others will love this, too.
> 
> This is fun and all, but it's not clear to me why this is desirable
> over, say:
> 
>     % tasn "call Tom's friend"

The technical answer is two-fold:

1) I may not know ahead of time if I double quotes are needed and would 
rather not have to go back and insert if I forget them.
2) I could address this by always putting in double quotes. But that's 
four keystrokes I'd rather not have to type if I don't have to. And 
actually, it's more like thousands upon thousand of keystrokes over a 
few years time. A 1/2 second here and there eventually adds up to hours 
typing a key I don't have. Why would I want to do that?

The non-technical answer is that computers should accommodate us, not 
vice versa. I shouldn't have to be knowledgeable about my shell to 
interact with an application. A good application should be accessible to 
non-technical users who may have no idea why they need to type in a 
slash into a sentence meant for humans to input and read.

So I can now introduce this program to my wife who knows nothing of 
shells and I don't have to explain to her "always surround the tasks 
with double quotes but if you want to use a double quote in between 
those quotes you have to escape it with a back slash (no, not that one, 
the one above the 'return' key). That would be a non-starter.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Is there any possible way to automatically escape characters when executing an alias in zsh?
  2021-09-11 22:39           ` Lawrence Velázquez
  2021-09-11 23:15             ` Steve Dondley
@ 2021-09-11 23:17             ` Bart Schaefer
  2021-09-11 23:33               ` Steve Dondley
  2021-09-12  3:33               ` Ray Andrews
  1 sibling, 2 replies; 16+ messages in thread
From: Bart Schaefer @ 2021-09-11 23:17 UTC (permalink / raw)
  To: Lawrence Velázquez; +Cc: Steve Dondley, Zsh Users

On Sat, Sep 11, 2021 at 11:41 AM Steve Dondley <s@dondley.com> wrote:
>
> tasn call Tom's friend
>
> This will thrown an error unless I escape the apostrophe.

Sorry, why does this produce an error?

% tasn call Tom's friend
quote>

Do you use setopt cshjunkiequotes ?

> I don't want to turn these into functions because then I lose the
> autocomplete capabilities.

Turning them into functions wouldn't help with quote parsing anyway.

On Sat, Sep 11, 2021 at 3:39 PM Lawrence Velázquez <larryv@zsh.org> wrote:
>
> This is fun and all, but it's not clear to me why this is desirable
> over, say:
>
>     % tasn "call Tom's friend"

PWS's solution is also going to produce this result:

% tasn call 'double "quotes" here'
tasn call \'double "quotes" here\'

which is probably not the desired effect?

Figuring out which quotes mean something and which ought to be
re-quoted is not a trivial matter.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Is there any possible way to automatically escape characters when executing an alias in zsh?
  2021-09-11 23:17             ` Bart Schaefer
@ 2021-09-11 23:33               ` Steve Dondley
  2021-09-12  3:33               ` Ray Andrews
  1 sibling, 0 replies; 16+ messages in thread
From: Steve Dondley @ 2021-09-11 23:33 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Lawrence Velázquez, Zsh Users


> Sorry, why does this produce an error?

Ok, it's not technically producing an error in the shell but it is an 
error with taskwarrior. It doesn't respond properly. Other kinds of 
punctuation will also cause more serious problems and confusion. Like 
'&'.

> % tasn call Tom's friend
> quote>
> 
> Do you use setopt cshjunkiequotes ?

No, not familiar with it. But as mentioned above, quotes aren't the only 
problematic punctuation characters. So I'm not sure that would work.


> PWS's solution is also going to produce this result:
> 
> % tasn call 'double "quotes" here'
> tasn call \'double "quotes" here\'
> 
> which is probably not the desired effect?

I just tried it with taskwarrior. The double quote are stripped out. But 
it's unlikely I'd ever write a task like that. 99% of the time the 
problem I have is with me having to escape (or forgetting to escape), 
parentheses and apostrophes.

> Figuring out which quotes mean something and which ought to be
> re-quoted is not a trivial matter.

True, but I'm not going to let the perfect be then enemy of the pretty 
damn good.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Is there any possible way to automatically escape characters when executing an alias in zsh?
  2021-09-11 23:15             ` Steve Dondley
@ 2021-09-12  0:23               ` Bart Schaefer
  2021-09-12  1:27                 ` Steve Dondley
  0 siblings, 1 reply; 16+ messages in thread
From: Bart Schaefer @ 2021-09-12  0:23 UTC (permalink / raw)
  To: Steve Dondley; +Cc: Lawrence Velázquez, Zsh Users

On Sat, Sep 11, 2021 at 4:33 PM Steve Dondley <s@dondley.com> wrote:
>
> Ok, it's not technically producing an error in the shell but it is an
> error with taskwarrior. It doesn't respond properly. Other kinds of
> punctuation will also cause more serious problems and confusion. Like
> '&'.

If you're never using these commands in any sort of pipeline or other
structured shell input, why are you using a general-purpose shell for
this at all?  Why not write a taskwarrior front-end that does nothing
but read literal lines without interpretation and pass them along?

On Sat, Sep 11, 2021 at 5:04 PM Steve Dondley <s@dondley.com> wrote:
>
> I just tried on another computer without the escaping function PWS wrote
> and taskwarrior strips out all double quotes unless they are escaped.

I think you'll find it's the shell that's removing (interpreting) the
quotes, not taskwarrior.


On Sat, Sep 11, 2021 at 4:15 PM Steve Dondley <s@dondley.com> wrote:
>
> The non-technical answer is that computers should accommodate us, not
> vice versa. I shouldn't have to be knowledgeable about my shell to
> interact with an application.

But you aren't interacting with "an application" in the sense that you
mean it.  You're interacting with the shell, which has explicit syntax
rules so that you can precisely describe what you intend to have it
do.

> A good application should be accessible to
> non-technical users who may have no idea why they need to type in a
> slash into a sentence meant for humans to input and read.

You're in effect arguing that this input should not be on a shell
command line and instead should always be consumed separately, so that
the shell doesn't have to interpret it first.

If the only thing that ever follows "tasn" is something that's
supposed to be a human-readable sentence interpreted exactly as typed,
you can skip the whole business of messing about with checking for
quotes etc., but the fact that you're worried about autocompletion
suggests that is not the case.

On Sat, Sep 11, 2021 at 11:41 AM Steve Dondley <s@dondley.com> wrote:
>
> I have many aliases set up for taskwarrior in zsh:
>
> alias tasn="task +sn add"`

I'm going to assume that the trailing backquote there is a typo.
Here's a modification of PWS's widget, that really does take
everything after the word "tasn" (or any other word beginning with
"ta" or "tm") as raw human-readable text:

taskwarrior-literal() {
  setopt localoptions extendedglob
  local -a match
  # Assumes human never types tab or backslash
  # and everything after the first word is literal
  if [[ -z ${BUFFER/(#s)(#b)((ta|tm)[a-z](#c1,) )(*)/} &&
        $match[3] != *\\* ]]
  then BUFFER="$match[1] ${(@q)${=match[3]}}"
  fi
}
zle -N taskwarrior-literal
autoload add-zle-hook-widget
add-zle-hook-widget line-finish taskwarrior-literal


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Is there any possible way to automatically escape characters when executing an alias in zsh?
  2021-09-12  0:23               ` Bart Schaefer
@ 2021-09-12  1:27                 ` Steve Dondley
  2021-09-12  2:26                   ` Bart Schaefer
  0 siblings, 1 reply; 16+ messages in thread
From: Steve Dondley @ 2021-09-12  1:27 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Lawrence Velázquez, Zsh Users


> If you're never using these commands in any sort of pipeline or other
> structured shell input, why are you using a general-purpose shell for
> this at all?  Why not write a taskwarrior front-end that does nothing
> but read literal lines without interpretation and pass them along?

This is how taskwarrior works out of the box, through the shell. Others 
have written front ends for TW: https://github.com/vit-project/vit

But I'm 99% happy using TW through the command line especially since it 
allows me to write my own functions to speed up entering tasks with 
command arguments I use regularly. It wouldn't be a good idea to throw 
out the baby with the bath water and write my own front end or move to 
some front end that I may or may not be able to hack to behave as I wish 
to address this minor annoyance.

> I think you'll find it's the shell that's removing (interpreting) the
> quotes, not taskwarrior.

Ok, yeah, didn't think about that.

> But you aren't interacting with "an application" in the sense that you
> mean it.  You're interacting with the shell, which has explicit syntax
> rules so that you can precisely describe what you intend to have it
> do.

I don't agree with this statement. If I launch a command with the shell 
and pass it some argument to open up a full-blown GUI for with a 
particular color theme, that doesn't mean I'm interacting with the 
shell. The shell is just a useful go-between and then it gets out of my 
way. Similarly, the shell is just a useful go-between for manipulating 
the TW database. I (usually) want it to get out of the way and leave me 
alone when I do that. I only want the shell to reveal itself at the 
appropriate times (like writing aliases and functions). But the more it 
can get out of the way when I'm trying to achieve my goal of 
manipulating the TW database, the better. For me to have to worry about 
making the shell happy when entering tasks is a nuisance I'd prefer not 
to deal with.

> You're in effect arguing that this input should not be on a shell
> command line and instead should always be consumed separately, so that
> the shell doesn't have to interpret it first.

No, I'm saying that I personally would like to get the best of both 
worlds, if possible. And why wouldn't I?

And what could possibly be the harm in having the shell do some typing 
for me without me having to think about it? Isn't that what computers 
are for, to automate things for us?

> If the only thing that ever follows "tasn" is something that's
> supposed to be a human-readable sentence interpreted exactly as typed,
> you can skip the whole business of messing about with checking for
> quotes etc., but the fact that you're worried about autocompletion
> suggests that is not the case.

Correct, I can type in pro<tab> and it will autocomplete to "project:" 
for me. It can also autocomplete project names as and perform other 
minor completions (none of which will ever contain special characters 
that need to be escaped).

> I'm going to assume that the trailing backquote there is a typo.
> Here's a modification of PWS's widget, that really does take
> everything after the word "tasn" (or any other word beginning with
> "ta" or "tm") as raw human-readable text:
> 
> taskwarrior-literal() {
>   setopt localoptions extendedglob
>   local -a match
>   # Assumes human never types tab or backslash
>   # and everything after the first word is literal
>   if [[ -z ${BUFFER/(#s)(#b)((ta|tm)[a-z](#c1,) )(*)/} &&
>         $match[3] != *\\* ]]
>   then BUFFER="$match[1] ${(@q)${=match[3]}}"
>   fi
> }
> zle -N taskwarrior-literal
> autoload add-zle-hook-widget
> add-zle-hook-widget line-finish taskwarrior-literal

Yeah, so I don't think this would work because I need <tab> for 
autocompletion. Or am I not understanding this?


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Is there any possible way to automatically escape characters when executing an alias in zsh?
  2021-09-12  1:27                 ` Steve Dondley
@ 2021-09-12  2:26                   ` Bart Schaefer
  2021-09-12  3:02                     ` Steve Dondley
  0 siblings, 1 reply; 16+ messages in thread
From: Bart Schaefer @ 2021-09-12  2:26 UTC (permalink / raw)
  To: Steve Dondley; +Cc: Zsh Users

On Sat, Sep 11, 2021 at 6:27 PM Steve Dondley <s@dondley.com> wrote:
>
> If I launch a command with the shell
> and pass it some argument to open up a full-blown GUI for with a
> particular color theme, that doesn't mean I'm interacting with the
> shell.

You're interacting with the up the point where you launch the command,
and then you're interacting with the application you launched.

> And what could possibly be the harm in having the shell do some typing
> for me without me having to think about it?

Having the shell do some typing for you is not the same as having the
shell ignore something you typed in a context where it would normally
pay attention.  Eventually you're going to type something the shell
should not have ignored and the wrong thing is going to happen.

See for example url-quote-magic.  That does the typing for you, and
you can see what it did to make sure it didn't do anything wrong.
PWS's solution (and even my edit thereof) change the input at a time
and place where it's too late for you to fix anything that's awry.

> > zle -N taskwarrior-literal
> > autoload add-zle-hook-widget
> > add-zle-hook-widget line-finish taskwarrior-literal
>
> Yeah, so I don't think this would work because I need <tab> for
> autocompletion. Or am I not understanding this?

You're not understanding.  Given that you said --
> minor completions (none of which will ever contain special characters
> that need to be escaped)
-- taskwarrior-literal should work fine.  As with PWS's suggestion,
this kicks in when you press enter (accept-line), so all your
completions are already out of the way, and it only quotes things that
need quoting.  The difference is that it blindly quotes ANYTHING that
might be interpreted by the shell, including filename globs, etc.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Is there any possible way to automatically escape characters when executing an alias in zsh?
  2021-09-12  2:26                   ` Bart Schaefer
@ 2021-09-12  3:02                     ` Steve Dondley
  0 siblings, 0 replies; 16+ messages in thread
From: Steve Dondley @ 2021-09-12  3:02 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users


> See for example url-quote-magic.  That does the typing for you, and
> you can see what it did to make sure it didn't do anything wrong.
> PWS's solution (and even my edit thereof) change the input at a time
> and place where it's too late for you to fix anything that's awry.

I can't think of a scenario off the top of my head but I'm not saying 
you're wrong. Yes, it's hacky. However, issuing a bad command to TW is 
not some mission critical problem that can't be easily reversed. Doing 
the risk/reward calculus, it seems to have far more upsides than 
potential downs.

I wouldn't recommend this as an official part of the TW release, but 
since this is just a hack for my own use and convenience, I see no harm 
in deploying it.

> You're not understanding.  Given that you said --
>> minor completions (none of which will ever contain special characters
>> that need to be escaped)
> -- taskwarrior-literal should work fine.  As with PWS's suggestion,
> this kicks in when you press enter (accept-line), so all your
> completions are already out of the way,

OK, right.

and it only quotes things that
> need quoting.  The difference is that it blindly quotes ANYTHING that
> might be interpreted by the shell, including filename globs, etc.

I have modified PWS' solution to this:

accept-with-quote() {
   if [[ $BUFFER = (tasn|tast|ta|tat|tm|taa|tai|tau|task)' '* && $BUFFER 
!= *\\* ]]; then
       BUFFER=${BUFFER//\'/\\\'}
       BUFFER=${BUFFER//\(/\\\(}
       BUFFER=${BUFFER//\)/\\\)}
       BUFFER=${BUFFER//\&/\\\&}
   fi
}

This doesn't look nearly as elegant as your solution. But I can (mostly) 
understand it and modify it myself, which is probably more important for 
a zsh newb like me.

But huge thanks for your time and input. I enjoying kicking the ball 
around on this stuff. Helps me learn.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: Is there any possible way to automatically escape characters when executing an alias in zsh?
  2021-09-11 23:17             ` Bart Schaefer
  2021-09-11 23:33               ` Steve Dondley
@ 2021-09-12  3:33               ` Ray Andrews
  1 sibling, 0 replies; 16+ messages in thread
From: Ray Andrews @ 2021-09-12  3:33 UTC (permalink / raw)
  To: zsh-users

On 2021-09-11 4:17 p.m., Bart Schaefer wrote:
>
> Figuring out which quotes mean something and which ought to be
> re-quoted is not a trivial matter.
>
If any special character were to be automatically escaped, even if it 
could be done, would it not implicitly break the normal use of that 
character?  Surely it is best to just use the shell syntax as it is 
meant to be used even if that does cost a keystroke or two? Quoting and 
escaping is one of the more understandable aspects of the shell why not 
use the syntax as it is?  Dunno, every time I try to get zsh to do 
something she doesn't want to do I end up regretting it.  Type the 
escape and be done with it.  Just my two cents.


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2021-09-12  3:34 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-11 18:41 Is there any possible way to automatically escape characters when executing an alias in zsh? Steve Dondley
2021-09-11 19:00 ` zzapper
2021-09-11 19:16 ` Peter Stephenson
2021-09-11 19:28   ` Peter Stephenson
2021-09-11 20:45     ` Steve Dondley
2021-09-11 20:53       ` Peter Stephenson
2021-09-11 21:01         ` Steve Dondley
2021-09-11 22:39           ` Lawrence Velázquez
2021-09-11 23:15             ` Steve Dondley
2021-09-12  0:23               ` Bart Schaefer
2021-09-12  1:27                 ` Steve Dondley
2021-09-12  2:26                   ` Bart Schaefer
2021-09-12  3:02                     ` Steve Dondley
2021-09-11 23:17             ` Bart Schaefer
2021-09-11 23:33               ` Steve Dondley
2021-09-12  3:33               ` Ray Andrews

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).