zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: Steve Dondley <s@dondley.com>
Cc: "Lawrence Velázquez" <larryv@zsh.org>, "Zsh Users" <zsh-users@zsh.org>
Subject: Re: Is there any possible way to automatically escape characters when executing an alias in zsh?
Date: Sat, 11 Sep 2021 17:23:39 -0700	[thread overview]
Message-ID: <CAH+w=7bh80GP-50wXcm7COhT4A6TK3+=PVVHcJdqVbC81gFQ8A@mail.gmail.com> (raw)
In-Reply-To: <de07d596ee7174b28dd6757979b44917@dondley.com>

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


  reply	other threads:[~2021-09-12  0:24 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-11 18:41 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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAH+w=7bh80GP-50wXcm7COhT4A6TK3+=PVVHcJdqVbC81gFQ8A@mail.gmail.com' \
    --to=schaefer@brasslantern.com \
    --cc=larryv@zsh.org \
    --cc=s@dondley.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).