How to disable zsh substitution/autocomplete with URL and backslashes

浪尽此生 提交于 2019-11-29 14:41:58

问题


I am using zsh with oh-my-zsh on Ubuntu:14.04.

The shell autocompletes escape character with backslash when I paste a URL.

For example with environment variables:

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

How can I disable this function?


回答1:


update 2019-05-12:

new version(> 486fa10) oh-my-zsh have a configuration for this, add DISABLE_MAGIC_FUNCTIONS=true before source $ZSH/oh-my-zsh.sh:

DISABLE_MAGIC_FUNCTIONS=true
source $ZSH/oh-my-zsh.sh

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


Original answer:

This is a bug in zsh 5.1.1 ~ 5.2(current).

The plugin bracketed-paste-magic did not works in the zsh versions.

The issue is here:

  • https://github.com/zsh-users/zsh-autosuggestions/issues/102
  • https://github.com/robbyrussell/oh-my-zsh/issues/5499
  • https://github.com/robbyrussell/oh-my-zsh/commit/35517457921c095be1aa6ed948debfbe183b89ac

I suggest you disable bracketed-paste-magic.

Comment these code from oh-my-zsh's ~/.oh-my-zsh/lib/misc.zsh solve the problem:

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

via




回答2:


If the URL is not quoted, the backslashes may be necessary, that's why zsh adds them (via url-quote-magic). If you do not like them, then quote the URL:

$ wget '

then paste the URL and type the ending quote:

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

To disable the url-quote-magic feature entirely:

zstyle ':urlglobber' url-other-schema

EDIT: As of version 5.1, zsh supports bracketed paste in some terminals, in which case url-quote-magic is no longer involved (bracketed-paste-magic replaces it for pastes).




回答3:


show my zsh version

echo $ZSH_VERSION
5.3

open misc.zsh

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

you will see the following:

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

add the following line at the top of the file

DISABLE_MAGIC_FUNCTIONS=true


来源:https://stackoverflow.com/questions/25614613/how-to-disable-zsh-substitution-autocomplete-with-url-and-backslashes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!