Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Avoiding the zshells intelligence...in one case

On Sun, 22 Jan 2017, Meino.Cramer@xxxxxx wrote:

> Previously I used commands like
>     zscript 'http://<URL>'
> but over the time I get annoyed by the '' since the
> stuff in between was cute'n'pasted from somewhere else.
> Is there any way to write a script/alias which takes
> its first/nth argument verbatim and character by character
> without any intelligent intervention of the zshell?

You have a few choices:

One is to use url-quote-magic (and possibly one of bracketed-paste-magic
or bracketed-paste-url-magic) so that the quoting is done for you by the
editor when you enter the URL.

Another is to use the "noglob" modifier, although that won't quote things
that look like other expansions, so if your URLs contain "$" or "{" "}"
all the following will fall short.


alias zscript='noglob zscript'

However, this will apply to all arguments, not just the first.  So one
workaround is this convoluted looking thing:

# Quote the first N-1 arguments [of the alias] and glob the Nth+
globN+ () { ${(b)@[2,$1+1]} ${~@[$1+2,-1]} }
alias zscript='noglob globN+ 2 zscript'

You can perhaps see how to extend that to quoting specific positions.

(Aside to zsh-workers, it'd be nice if "noglob function { body } args"
worked to call an anonymous function without globbing.  Hard, I bet.)

The most radical choice is to "setopt nonomatch", but that's probably more
than what you want.  However, you can combine that with noglob:

nonomatch() { setopt localoptions nonomatch; ${~@} }
alias zscript='noglob nonomatch zscript'

Note this doesn't recursively expand the alias because alias expansion
occurs before parameter expansion, so $1 will always be looked up as a
function, builtin, or command within the nonomatch function.

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