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, Sep 11, 2021 at 4:33 PM Steve Dondley <s@xxxxxxxxxxx> 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@xxxxxxxxxxx> 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@xxxxxxxxxxx> 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@xxxxxxxxxxx> 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




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