我正在使用zsh
和oh-my-zsh
在Ubuntu:14.04上。
当我粘贴URL时,Shell将转义字符自动补全为反斜杠。
例如,对于环境变量:
$ wget http://{DEFAULT_IP}/index.html
It will become:
$ wget http://\{DEFAULT_IP\}/index.html
我该如何禁用这个功能?
更新于2019年5月12日:
新版本(> 486fa10)的oh-my-zsh已经有了这个配置,只需在source $ZSH/oh-my-zsh.sh
之前添加DISABLE_MAGIC_FUNCTIONS=true
即可:
DISABLE_MAGIC_FUNCTIONS=true
source $ZSH/oh-my-zsh.sh
通过链接查看:https://github.com/robbyrussell/oh-my-zsh/commit/486fa1010df847bfd8823b4492623afc7c935709
原始回答:
这是zsh 5.1.1 ~ 5.2(当前版本)中的一个错误。
插件bracketed-paste-magic
在zsh版本中无法正常工作。
问题出在这里:
bracketed-paste-magic
。~/.oh-my-zsh/lib/misc.zsh
中注释掉即可解决问题。if [[ $ZSH_VERSION != 5.1.1 ]]; 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
bracketed-paste-magic
插件是用来做什么的?为什么官方的ohmyzsh不禁用它。 - Ertuğrul AltınboğaDISABLE_MAGIC_FUNCTIONS="true"
- DimiDak如果URL没有加引号,反斜杠可能是必需的,这就是为什么zsh会添加它们(通过url-quote-magic
)。如果你不喜欢它们,那么请给URL加上引号:
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
取而代之用于粘贴)。
.zshrc
结尾和您的 .zlogin
结尾(两者都可能需要:.zshrc
因为 .zlogin
不总是被调用,.zlogin
因为它在 .zshrc
之后被调用)。 - vinc17bracketed-paste-magic
或使用 backward-extend-paste
,这样 bracketed-paste-magic
就可以在上下文中看到引号。注意:我已经编辑了我的答案,提到了一个新功能——括号粘贴。 - vinc17显示我的zsh版本
echo $ZSH_VERSION
5.3
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