8

On macOS Catalina, when I copy text and paste to Terminal, the text is highlighted (basically, there are ANSI color codes enclosing the text). I don't know when this feature was included, but is there a way to disable it?

1 Answer 1

9

As of macOS Catalina, the default shell for new accounts is now zsh instead of bash.

zsh has a feature called "bracketed paste" that allows the shell, specifically the zsh's line-editing mode known as "zle", to handle pasted text differently than if the same text had been typed in one character at a time, assuming your terminal emulator supports it, which macOS's built-in Terminal.app does. It's this "zsh line editing bracketed paste" that's highlighting your text.

To disable this feature, unset the "zle_bracketed_paste" environment variable:

% unset zle_bracketed_paste

You should be able to add that command to an appropriate shell startup script so that it's invoked every time (putting it in ~/.zlogin worked for me).

Or you could switch your shell to bash if that's what you'd prefer:

% chsh -s /bin/bash

If you'd like to learn more about zsh's line editing mode's support for bracketed paste, see the zshzle and zshparam man pages.

Catalina's built-in version of bash is pretty old and doesn't support bracketed-paste, but the latest versions of bash do, so if you've installed, and are running, a version of bash recent enough to support bracketed-paste, you can disable it with the command bind "set enable-bracketed-paste off". You can add that bind command to the appropriate bash shell startup file for your situation, or you can add just the set enable-bracketed-paste off part of it to your ~/.inputrc.

2
  • I have bash from homebrew already $ echo $SHELL /usr/local/bin/bash. $ bash --version GNU bash, version 5.1.4(1)-release (x86_64-apple-darwin19.6.0) Copyright (C) 2020 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Does bash also add color code when copying? Or it is due to something else? Commented Feb 3, 2021 at 3:19
  • 1
    Yes, the version of bash you installed with Homebrew has its own form of bracketed-paste support. You can disable it with the command bind "set enable-bracketed-paste off". You can add that bind command to the appropriate bash shell startup file for your situation, or you can add just the "set…" part of it to your ~/.inputrc.
    – Spiff
    Commented Feb 3, 2021 at 3:37

You must log in to answer this question.

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