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

时间:2014-09-02 01:22:17

标签: zsh zshrc oh-my-zsh

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

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

例如,使用环境变量:

$ wget http://{DEFAULT_IP}/index.html
It will become:
$ wget http://\{DEFAULT_IP\}/index.html

如何禁用此功能?

4 个答案:

答案 0 :(得分:20)

更新2019-05-12:

新版本(> 486fa10)哦-my-zsh有一个配置,在svg之前添加DISABLE_MAGIC_FUNCTIONS=true

source $ZSH/oh-my-zsh.sh

via:https://github.com/robbyrussell/oh-my-zsh/commit/486fa1010df847bfd8823b4492623afc7c935709

原始答案:

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

插件DISABLE_MAGIC_FUNCTIONS=true source $ZSH/oh-my-zsh.sh 在zsh版本中不起作用。

问题在于:

我建议您停用bracketed-paste-magic

评论来自oh-my-zsh bracketed-paste-magic的这些代码解决问题:

~/.oh-my-zsh/lib/misc.zsh

via

答案 1 :(得分:8)

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

$ wget '

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

$ wget 'http://{DEFAULT_IP}/index.html'

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

zstyle ':urlglobber' url-other-schema

编辑:从版本5.1开始,zsh在某些终端中支持括号粘贴,在这种情况下url-quote-magic不再参与(bracketed-paste-magic将其替换为浆料)。

答案 2 :(得分:0)

显示我的zsh版本

echo $ZSH_VERSION
5.3

打开misc.zsh

vim ~/.oh-my-zsh/lib/misc.zsh

您将看到以下内容:

autoload -Uz is-at-least

# *-magic is known buggy in some versions; disable if so
if [[ $DISABLE_MAGIC_FUNCTIONS != true ]]; then
  for d in $fpath; do
    if [[ -e "$d/url-quote-magic" ]]; then
        if is-at-least 5.1; then
            autoload -Uz bracketed-paste-magic
            zle -N bracketed-paste bracketed-paste-magic
        fi
        autoload -Uz url-quote-magic
        zle -N self-insert url-quote-magic
      break
    fi
  done
fi

## jobs
setopt long_list_jobs

env_default 'PAGER' 'less'
env_default 'LESS' '-R'

## super user alias
alias _='sudo'

## more intelligent acking for ubuntu users
if which ack-grep &> /dev/null; then
  alias afind='ack-grep -il'
else
  alias afind='ack -il'
fi

# only define LC_CTYPE if undefined
if [[ -z "$LC_CTYPE" && -z "$LC_ALL" ]]; then
    export LC_CTYPE=${LANG%%:*} # pick the first entry from LANG
fi

# recognize comments
setopt interactivecomments

在文件顶部添加以下行

DISABLE_MAGIC_FUNCTIONS=true

答案 3 :(得分:0)

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

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

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

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

iTerm2 - Disable paste bracketing