zsh 中的自动引用参数

luq*_*qui 2 zsh command-line

这是一个很遥远的事情,但我想知道是否有一种方法可以使用zsh某些命令自动引用该行的其余部分。例如,对于命令he

he (foo*bar + baz)^2
Run Code Online (Sandbox Code Playgroud)

我希望它像我写的那样解析

he '(foo*bar + baz)^2'
Run Code Online (Sandbox Code Playgroud)

原因是我喜欢调用 Perl 或 Haskell 来完成某些任务,并且我不喜欢担心引用(特别是因为有时我有理由在表达式中使用单引号)。

Alo*_*xaf 6

我认为rc_quotes选择已经足够好了。

RC_QUOTES
       Allow the character sequence  `'''  to  signify  a  single  quote
        within singly quoted strings.  Note this does not apply in quoted
        strings using the format $'...', where a backslashed single quote
        can be used.
Run Code Online (Sandbox Code Playgroud)

但如果您愿意,您可以编写一个自定义接受行小部件来自动报价。

这是一个例子,它会引用后面的所有内容python -c

RC_QUOTES
       Allow the character sequence  `'''  to  signify  a  single  quote
        within singly quoted strings.  Note this does not apply in quoted
        strings using the format $'...', where a backslashed single quote
        can be used.
Run Code Online (Sandbox Code Playgroud)

将这些代码复制到您的~/.zshrc.