如何使用URL和反斜杠禁用zsh替换/自动完成

Ert*_*oğa 8 zsh zshrc oh-my-zsh

我使用zshoh-my-zsh在Ubuntu:14.04.

当我粘贴URL时,shell使用反斜杠自动填充转义字符.

例如,使用环境变量:

$ wget http://{DEFAULT_IP}/index.html
It will become:
$ wget http://\{DEFAULT_IP\}/index.html
Run Code Online (Sandbox Code Playgroud)

如何禁用此功能?

als*_*swl 23

这是zsh 5.1.1~5.2(当前)中的错误.

该插件DISABLE_MAGIC_FUNCTIONS=true在zsh版本中不起作用.

问题在于:

我建议你禁用source $ZSH/oh-my-zsh.sh.

从oh-my-zsh中注释这些代码可以bracketed-paste-magic解决问题:

DISABLE_MAGIC_FUNCTIONS=true
source $ZSH/oh-my-zsh.sh
Run Code Online (Sandbox Code Playgroud)

通过

  • 这个插件的“bracketed-paste-magic”有什么用?为什么 ohmyzsh 官方不禁用它。 (2认同)

Mon*_*pit 9

我最终得到了这个答案,但仍然无法理解为什么粘贴 URL 会转义字符& ? [ ]并导致我的 curl 命令失败。

罪魁祸首(对我而言)是 Mac 上的 iTerm2。

要禁用该行为,请进入iTerm2 > Preferences > Profiles > Terminal并取消选中Terminal may enable paste bracketing

确保为正确的配置文件执行此操作。

iTerm2 - 禁用粘贴包围

  • 如果您在 Iterm2 中使用 oh-my-zsh,则需要在源 oh-my-zsh.sh 之前插入 `DISABLE_MAGIC_FUNCTIONS=true`,如上所述,否则您仍然会看到相同的问题。 (2认同)

vin*_*c17 8

如果没有引用URL,则可能需要使用反斜杠,这就是zsh添加它们(via url-quote-magic)的原因.如果您不喜欢它们,请引用URL:

$ wget '
Run Code Online (Sandbox Code Playgroud)

然后粘贴URL并输入结束引号:

$ wget 'http://{DEFAULT_IP}/index.html'
Run Code Online (Sandbox Code Playgroud)

url-quote-magic完全禁用该功能:

zstyle ':urlglobber' url-other-schema
Run Code Online (Sandbox Code Playgroud)

编辑:从版本5.1开始,zsh 在某些终端支持括号粘贴,在这种情况下url-quote-magic不再涉及(bracketed-paste-magic替换为粘贴).