From: "Sam B." <me@rmz.io>
To: zsh-users@zsh.org
Subject: Re: Disable most shell expansion to function or script
Date: Sun, 14 Jan 2024 23:28:33 +0000 [thread overview]
Message-ID: <7jlvvie4lgnkreygh5z45cfglg4kotgy4fwf6ovgrkwg7imstg@hjxjrtstu5ov> (raw)
In-Reply-To: <gvuvj4y7ccszfuh7eob4etwiuc43tg3pn227bngajmch3haf6w@oegt6cnp4r6p>
[-- Attachment #1: Type: text/plain, Size: 1738 bytes --]
On Jan 05, 2024 at 17:53, Sam B. wrote:
> I'll have a read through `url-quote-magic` too, which seems to do
> something similar.
I quite liked the behaviour of `url-quote-magic` to simply type any of
the "special" chars and have them automatically quoted. So I've modified
`url-quote-magic` to escape chars only when the first word matches
`task` or any alias to it.
There's probably a few improvements possible, but here's a first pass of
my solution.
zstyle -m ':task-quote-magic:\*' task-seps '*' ||
zstyle -e ':task-quote-magic:*' task-seps 'reply=("#{}&<>''${histchars[1]}")'
zstyle -m ':task-quote-magic' task-cmds '*' ||
zstyle -e ':task-quote-magic' task-cmds \
'zmodload -i zsh/parameter;
reply=( task
${(k)galiases[(R)(* |)task *]:-}
${(k)aliases[(R)(* |)task *]:-} )'
function task-quote-magic {
setopt localoptions noksharrays extendedglob
local qkey="${(q)KEYS}"
local -a reply match mbegin mend
# is key different than quoted key
if [[ "$KEYS" != "$qkey" ]]
then
local lbuf="$LBUFFER$qkey"
if [[ "${(Q)LBUFFER}$KEYS" == "${(Q)lbuf}" ]]
then
local -a words
words=("${(@Q)${(z)lbuf}}")
local taskseps taskcmds
zstyle -s ":task-quote-magic" task-cmds taskcmds '|'
if [[ "$words[1]" == (#b)${~taskcmds} ]]
then
zstyle -s ":task-quote-magic:$match[1]" task-seps taskseps ''
fi
[[ "$taskseps" == *"$KEYS"* ]] &&
LBUFFER="$LBUFFER\\"
fi
fi
zle .self-insert
}
zle -N self-insert task-quote-magic
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
prev parent reply other threads:[~2024-01-14 23:30 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-04 18:09 Sam B.
2024-01-04 18:55 ` Stephane Chazelas
2024-01-04 19:16 ` Mikael Magnusson
2024-01-04 23:38 ` Bart Schaefer
2024-01-05 17:53 ` Sam B.
2024-01-14 23:28 ` Sam B. [this message]
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=7jlvvie4lgnkreygh5z45cfglg4kotgy4fwf6ovgrkwg7imstg@hjxjrtstu5ov \
--to=me@rmz.io \
--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).