bracketed paste mode

submited by
Style Pass
2023-03-19 20:30:06

One of the least well known, and therefore least used, features of many terminal emulators is bracketed paste mode. When you are in bracketed paste mode and you paste into your terminal the content will be wrapped by the sequences \e[200~ and \e[201~.

I admit this is hard to get excited about, but it turns out that it enables something very cool: programs can tell the difference between stuff you type manually and stuff you pasted.

Lots of terminal applications handle some characters specially: in particular when you hit your enter key it sends a newline. Most shells will execute the contents of the input buffer at that point, which is usually what you want. Unfortunately, this means that they will also run the contents of the input buffer if there’s a newline in anything you paste into the terminal.

I’m clumsy and often paste random stuff into my terminal; there was also a neat proof of concept for how to make usually not-clumsy people do the same. This can obviously be dangerous as your shell has the ability to do all kinds of things that you don’t want to happen by accident.

Leave a Comment