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:
signature.asc
Description: PGP signature