Dragging and dropping a file onto a Terminal window doesn’t escape the path under zsh 5.2

Under OS X you can drag and drop a file from the Finder (or anywhere else) onto a Terminal window and the file’s path will be inserted as if you had typed it in. Recently, filenames with spaces have stopped being handled correctly: if the file path contained spaces before, the Terminal would get a version enclosed in double quotes or else with each space preceded by a backslash. Now the entire file path is just dumped in, and if it contains any spaces then I have to go back and escape them myself.

I have played around with the “shells open with” setting and it seems that the correct escaping happens when the shell is /bin/bash (GNU bash 3.2.57(1)-release) or /bin/zsh (zsh 5.0.8) but not when the shell is my manually-installed /usr/local/bin/zsh (zsh 5.2). I’m on OS X 10.11.2.

Was there a change in zsh that could have messed up dragging and dropping in Terminal? Or is Terminal itself using some kind of whitelist of shells that doesn’t include my zsh?

Edit: I installed zsh 5.0.8 at /usr/local/bin/zsh and filenames are escaped properly for that shell. It seems that some change to zsh between versions 5.0.8 and 5.2 made this stop working.


This behavior seems to be caused by zsh’s bracketed paste feature, which is on by default as of version 5.1. I found that if I added

unset zle_bracketed_paste

to my zshrc then dropping files onto Terminal works correctly with zsh 5.2.

(This blog post mentions bracketed-paste-magic, which seems like it could be used to support dropping files without turning off the entire bracketed paste feature. I think you would need to write code to make that happen, though; simply turning on bracketed-paste-magic didn’t fix my problem.)


As mentioned in @bdesham’s answer, Zsh 5.1 introduced the use of the terminal's “Bracketed Paste Mode,” which allows terminal-based programs to differentiate pasted/dragged text from the user typing individual characters.

Terminal (at least as of OS X El Capitan 10.11.x) doesn't perform shell-quoting of pasted/dragged file pathnames when Bracketed Paste Mode is on, because prior to Zsh 5.1 BPM was only used by full-screen editors like Emacs and Vim, which don't normally need shell-quoting.

You can force shell-quoting to be applied when pasting/dragging by pressing the Control modifier key.