tl;dr:

  1. search in your ~/.zshrc file for source $ZSH/oh-my-zsh.sh and prepend this:
DISABLE_MAGIC_FUNCTIONS=true
  1. Open iTerm 2 Preferences, Profile Tab, Terminal Tab, untick this: Terminal may enable paste bracketing
  2. profit

This has been an annoyance for months or years now, and I never got around to fix it, since it was never too annoying, but rather just annoying. Let’s fix things! What exactly?

I’m an oh-my-zsh user and when you copy and paste things into the terminal, it’ll automatically put backslashes in front of various characters to make them work when executing the command, this usually happens when you’re pasting a URL into your terminal when you want to test something with curl for example.

Assume I have a URL and want to debug the output using curl. Naturally, I go ahead, copy the URL from my browser and paste it into my terminal. Now with oh-my-zsh enabled, the following happens:

original URL:

https://www.reddit.com/user/this-is-not-my-username/saved.json?feed=somethingrandom&user=this-is-not-my-username

this is how it’ll look like in my terminal:

https://www.reddit.com/user/this-is-not-my-username/saved.json\?feed\=somethingrandom\&user\=this-is-not-my-username

Depending on the URL, the tool, the script, whatever, you’ll get weird error messages that it couldn’t parse the input because of the backslashes.

fix for oh-my-zsh

this is actually just part 1: in order to fix this behavior for oh-my-zsh, you need to open your ~/.zshrc file and put this in front of source $ZSH/oh-my-zsh.sh:

DISABLE_MAGIC_FUNCTIONS=true

so it should look like this:

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

Next, either run source ~/.zshrc to apply changes or open a new terminal session/window/tab. Unfortunately, this is only half of the fix, at least if you’re also using iTerm 2.

fix for iTerm 2

  1. open up your iTerm 2 Settings
  2. open the Profile tab
  3. open the Terminal (sub)-tab
  4. untick Terminal may enable paste bracketing

see also this screenshot:

iterm 2 settings

as usual, thanks to the people on stack overflow