Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Disable most shell expansion to function or script
- X-seq: zsh-users 29417
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: Disable most shell expansion to function or script
- Date: Thu, 4 Jan 2024 15:38:30 -0800
- Archived-at: <https://zsh.org/users/29417>
- In-reply-to: <a2fkj5bgzxlsumj6a67fnff2yjhbiecch2hecbpoqll3fr6zmq@ysnu4kgkr76c>
- List-id: <zsh-users.zsh.org>
- References: <a2fkj5bgzxlsumj6a67fnff2yjhbiecch2hecbpoqll3fr6zmq@ysnu4kgkr76c>
On Thu, Jan 4, 2024 at 10:10 AM Sam B. <me@xxxxxx> wrote:
>
> I'm looking for a way to disable most shell expansion for the arguments
> to a script or function
> todo Text inc. $var, *glob?, events!, <redirs, >(sub) & more
accept-and-do-nothing() {
BUFFER=': !#:0:s/\://:p !"'"$BUFFER"
zle accept-line
}
zle -N accept-and-do-nothing
It's really difficult to avoid having the history references get
backslash-quoted ( in this example !, becomes \!, ), but otherwise
this skips everything.
What this does is:
- insert a : command as the word in command position.
- insert a history substitution that replaces that word with nothing
and then reprints the whole command without executing it
(substitution is to avoid doubling the first word when !#:0 is reprinted)
- insert the !" reference that disables history for the remainder of
the command line
- accept the result to add the whole thing to the history list
If "todo" is the only command for which you want this effect, you
could replace the ":" with "todo".
> Mostly I'm interested joting down some plain text which could include
> '?!&' and have "todo" receive it all without the shell having done some
> magic beforehand.
The foregoing could be augmented with a zshaddhistory hook to
recognize the magic first word and dump the rest of the line into a
file. Then
todo $(<thatfile)
would pass the whole thing unmodified into "todo" which would have to
"eval" it or something.
However, have you considered using edit-command-line (possibly
repeatedly) to jot things down, and then quote-region or similar when
happy before executing?
Messages sorted by:
Reverse Date,
Date,
Thread,
Author