11

I have already tried the solution at How to disable zsh substitution/autocomplete with URL and backslashes, but this is no longer working.

If I paste a URL, it keeps putting backslashes. Very annoying.

For example:

https://www.google.com?test=sample1&test2=sample3

will become:

curl -X POST "https://www.google.com\?test\=sample1\&test2\=sample3"

Here's the top of my ~/.zshrc file:

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation.
DISABLE_MAGIC_FUNCTIONS=true
export ZSH=/Users/myuser/.oh-my-zsh

I have already tried to re-call the source, no luck. The only way I've been able to get around this is to open up a bash shell instead, which can be extremely inconvenient.

LewlSauce
  • 5,326
  • 8
  • 44
  • 91
  • 1
    I can not reproduce it. Are you sure it is zsh doing it? What happens if you open a different subshell, for instance by typing `sh` or `dash` or `ksh`, and paste the string there. – user1934428 Jun 16 '20 at 07:37
  • Do the backslashes also appear if you paste the URL into between single quotes, i.e. you type `curl -X POST ''`, and then paste between the quotes? And what happens if the string to be pasted, does not look exactly like a complete URL, but is just (for instance) `sample1&test2`? – user1934428 Jun 16 '20 at 09:10
  • Yep! If I try with bash, it doesn't happen. It only happens in zshell. If I paste the URL in between quotes in zshell, still does the same thing. Will try shortly with a non URL – LewlSauce Jun 16 '20 at 11:03
  • 1
    This sounds related to the `url-quote-magic` widget. Backslashes *or* double-quoting the entire URL would be correct; both is not. What happens if you disable oh-my-zsh? – chepner Jun 16 '20 at 12:18
  • If I disable `oh-my-zsh` then I can paste the URL just fine without it adding the backslashes. The only plugin that I have in the plugins directory with "url" in it is urltools – LewlSauce Jun 17 '20 at 15:58
  • I added `DISABLE_MAGIC_FUNCTIONS="true"` to the top of my ~/.zshrc file and that fixed this issue. Can you post this as an answer so I can give you credit? – LewlSauce Jun 17 '20 at 16:07

2 Answers2

5

After search this worked for me

  1. open the file ~/.oh-my-zsh/lib/misc.zsh
  2. comment these lines below
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

the final result is

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 (( $+commands[ack-grep] )); then
  alias afind='ack-grep -il'
else
  alias afind='ack -il'
fi

# recognize comments
setopt interactivecomments

Relative Links

https://github.com/ohmyzsh/ohmyzsh/issues/5499

How to disable zsh substitution/autocomplete with URL and backslashes

Karim Elgazar
  • 164
  • 3
  • 4
0

I fixed it by updating oh-my-zsh version.

omz update

If you don't want nor are unable to update the version, You maybe can uncomment it (latest code at ~/.oh-my-zsh/lib/misc.zsh, I didn't test it though)

# *-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
Jongho Jeon
  • 96
  • 1
  • 3