ZSH keeps putting backslashes in my pasted URLS
Asked Answered
zsh
L

2

12

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.

Literatim answered 15/6, 2020 at 20:39 Comment(6)
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.Rutland
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?Rutland
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 URLLiteratim
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?Aureliaaurelian
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 urltoolsLiteratim
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?Literatim
P
6

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

Prey answered 15/7, 2020 at 15:56 Comment(0)
B
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
Burkle answered 30/8, 2023 at 9:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.