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.)

  • I had to add this to the end of my zsh file; it didn't work near the beginning. I didn't bother to determine why... – Marshall Eubanks Apr 20 '17 at 8:22

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.

  • 1
    And holding command gives you "cd /path/to/directory; " of the item if it was a directory, or of its parent otherwise. Cool! – Marshall Eubanks Apr 20 '17 at 8:11
  • It's a terminal issue that was fixed after 10.10. You can hack around it with a simbl plugin: github.com/fish-shell/fish-shell/issues/4323 – 1110101001 Aug 14 '17 at 5:40
  • I recently upgraded to GNU bash 5.1.4 (from an earlier GNU bash, perhaps 4.x or 5.0.x?) and found that the new version of bash doesn't escape spaces in files dragged to Terminal in OS X Mavericks 10.9.5—the same issue that this question reported for zsh 5.2. This answer provided the solution: Hold down the Control modifier key before releasing the drag. And I didn't know the Command modifier trick (for appending "cd") mentioned above either, so thanks! – Big Mac Apr 14 at 20:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .